Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

3151.

Solve : Rename files with % sign?

Answer»

I have a DIRECTORY with filenames that have a % (percent sign) in the name. I need to rename all files with "%" sign to an "_" underscore. Any ideas how I can create a loop to do this in DOS batch [not VB]?

The code below will convert spaces to underscores, not sure how to handle percent signs.

@echo off & setlocal enableextensions
pushd "%ENCRYPTED_PATH%"
for /f "tokens=*" %%f in ('
dir /b /a-d-s "%ENCRYPTED_PATH%\* *.*"') do (
set "_=%%~nxf"
call ren "%%~ff" "%%_: =_%%"
)
popd
endlocalI thought percent signs are illegal in Windows filenames, just how did these files get on your system?
The following should replace a percent sign with a # in each filename encountered. Remove echo when happy. I have not got any files with % in the name so I created a DUMMY set in a text file but this should work...

Code: [Select]@echo off
setlocal enabledelayedexpansion
dir /b /a-d-s "%ENCRYPTED_PATH%\* *.*" > test.txt
for /f "delims=" %%A in (test.txt) do (
set string1=%%A
set string2=!string1:%%=#!
echo ren "!string1!" "!string2!"
)

In cmd scripts ("batch files") you need to escape certain special characters. For many symbols the escape char is a CARET (^) but for a percent sign the escape character is... a percent sign. So double them up.

Quote from: Salmon Trout on October 27, 2009, 01:40:56 PM

I thought percent signs are illegal in Windows filenames, just how did these files get on your system?


The files are coming from some vendor, its the way they always create all the files on their sftp SERVER. Whatever happened with the simple naming standards.

Thanks for the code....
3152.

Solve : help neaded to process files?

Answer»

Hi all, i am looking for some HELP please

Basicly i have a program lets call it program.exe that doesn't support wildcards
what i want is a batch file to find say *.EXT in a folder and run the command on the found file, go back check again for anymore and process if necessary.

this sound so simple i cannot seam to work it out.



you want to run all .exe in folder ?i have a folder called somefolder
in this folder are some FILES called
aaaaaa.aaa
aaaaaa.bbb
aaaaaa.ccc
bbbbbb.aaa
bbbbbb.bbb
cccccc.aaa
etc

i have a program called prog.exe

i want to process all the *.aaa files

this works for a SINGLE file

Code: [Select]cd work
..\tools\prog.exe aaaaaa.aaa
exit
this won't work on multiple files

Code: [Select]cd work
..\tools\prog.exe *.aaa
exit
the prog.exe does not support wildcards
the prefix to the filename changes every time the batch is called
the extension is always the same
the folders are always the same
all you need is the for loop.can you post an example code that would work pleaseCode: [Select]@ECHO off
for /f %%a in ('dir /b *.aaa') do prog.exe %%a
pauseCode: [Select]@echo off
for /f "tokens=" %%A in ( ' dir /b *.aaa ' ) do (
echo Processing file %%A
start /WAIT "" "Path to\prog.exe" "%%A"
)
@for /r somefolder %%a in (*.aaa) do @prog "%%a"Thanks for all the fast replys and help got it working now

3153.

Solve : nbtstat bat file?

Answer»

I am trying to make a batch file were I can input an IP ADDRESS and it run "nbtstat -a (ip)" and it has been a while SENSE I last wrote a batch file, were is a GOOD place to start?C:\>type ipstat.bat
Code: [Select]nbtstat -a (%1)C:\> ipstat.bat 255.255.248.0

OUTPUT:

C:\>nbtstat -a (68.97.215.175)

Local Area CONNECTION:
Node IpAddress: [68.97.215.175] Scope ID: []

Host not found.

3154.

Solve : Starting a new window with the specified commands.?

Answer»

Quote from: BatchFileCommand on April 05, 2009, 03:19:58 PM

Thank you Dias, couldn't you have just posted that in the BEGGINING.

I didn't think of it until today, ALSO you have been very rude, so I decided to punish you.

18:03 = 6:03this is funny little util, pop up little window showing time-watch. only few lines. nice..

and then again i am going to preach about code readability
Code: [Select]@echo off>clock.bat

>>clock.bat echo @echo off
>>clock.bat echo mode con: cols=16 lines=2
>>clock.bat echo :loop
>>clock.bat echo echo %%time%%
>>clock.bat echo if not exist signal.txt goto loop
>>clock.bat echo exit

if exist signal.txt del signal.txt
start "" "cmd.exe" /c clock.bat
set /p string="Press ENTER to stop clock "
echo %string%>signal.txt

Code: [Select]@echo off
(
echo @echo off
echo mode con: cols=16 lines=2
echo :loop
echo echo %%time%%
echo if not exist signal.txt goto loop
echo exit
)>clock.bat & REM parantesis is not supported, escape with caret

if exist signal.txt del signal.txt
start/b "" "cmd.exe" /c clock.bat
set /p string="Press Enter to stop clock "
echo %string%>signal.txt
3155.

Solve : setting a delim as ONLY a space?

Answer»

I can't figure out the delimeter to set it as only a space without the tab.

I've tried:

Code: [Select]for /F "tokens=1-4 delims= " %%Z in ('COMMAND') do set output=%%Z

But I am always getting the delimeter of a tab and space.A tab is a special kind of space. Delims= really means space and tab. What command are you using, that outputs tabs, which would give a different result if you could ignore the tabs?

command | more

will strip the tabs out of command's output (In a FOR line don't forget to escape the | with a caret)





3156.

Solve : End process and delete file every 5 seconds?

Answer»

hey guys, having an issue with a virus that keeps REAPPEARING after i delete it, i am trying to temporaily fix this problem until a security update is released..

im not sure how to end a process through batch but i can delete with

@echo off
:loop
(put a timer in for 5 seconds)
(end procces)
del name.ext
goto loop


any help would really be appreciated, i think my works been hit with a NEW virus :s


batch is no way to solve a virus problem, this might just agitate it .

if you need an anti virus, there are many free
avast!
AVG
Bit defender

though if you are just looking for an answer, a simple timeout would
sleepQuote

Usage: sleep time-to-sleep-in-seconds
sleep [-m] time-to-sleep-in-milliseconds
sleep [-c] commited-memory ratio (1%-100%)

or using ping, replace 2 with the number of timeout you want
Quote
ping localhost -n 2 -w 1000 >nil

as for proccess kill, taskkill or tskill:
Code: [Select]TSKILL processid | processname [/SERVER:servername] [/ID:sessionid | /A] [/V]

processid Process ID for the process to be terminated.
processname Process name to be terminated.
/SERVER:servername Server containing processID (default is current).
/ID or /A must be specified when using processname
and /SERVER
/ID:sessionid End process running under the specified session.
/A End process running under ALL sessions.
/V Display information about ACTIONS being performed.yea i know, but its an exchange problem thats spamming our servers, like i said this is just temporary. ive found that i can use ping to set time but it looks very messy, any other way?sleep doesnt work, in XP anyway@echo off
:loop
tskill PROCESS (without .exe)
del File.ext
ping localhost -n 5 -w 1000>nul
goto loop

But PLEASE go to the computer viruses section to REMOVE your problem, not just hide a symptom. Quote from: Khasiar on OCTOBER 27, 2009, 04:44:31 PM
sleep doesnt work, in XP anyway

I use XP Pro and sleep works very well.

@echo off

Code: [Select]set /a c=0
:here
echo Sleep 3 seconds and repeat
echo when count is 10 quit
echo count = %c%
C:\batextra\sleep.exe 3

set /a c+=1

if %c% EQU 10 exit /b

goto here
OutPut:

C:\batextra> reploop.bat
Sleep 3 seconds and repeat
when count is 10 quit
count = 0
Sleep 3 seconds and repeat
when count is 10 quit
count = 1
Sleep 3 seconds and repeat
when count is 10 quit
count = 2
Sleep 3 seconds and repeat
when count is 10 quit
count = 3
Sleep 3 seconds and repeat
when count is 10 quit
count = 4
Sleep 3 seconds and repeat
when count is 10 quit
count = 5
Sleep 3 seconds and repeat
when count is 10 quit
count = 6
Sleep 3 seconds and repeat
when count is 10 quit
count = 7
Sleep 3 seconds and repeat
when count is 10 quit
count = 8
Sleep 3 seconds and repeat
when count is 10 quit
count = 9

C:\batextra>
3157.

Solve : spelling?

Answer»

wonder if he means by name meanings...

QUOTE from: macdad- on April 05, 2009, 03:21:14 PM

wonder if he means by name meanings...



Well you still couldn't do that with batch. UNLESS you had some 3p program...even then it would be strange.No this is possible, if you LIKE doing alot of tedious IF..THEN statements, he could go onto some name meaning site and search up a name one by one and add that to the code....but still to TRIVIAL and tedious to attempt.Quote from: Helpmeh on April 05, 2009, 12:47:48 PM
You can't change the ENGLISH letters in a name and get Japanese...

oh, I know it is just a game

however, I don't want to continue with that batch. Our alphabet is more beautiful

Thank you and excuse me please
3158.

Solve : Backgrounds?

Answer» HI everybody!

Any way to set a background to my batch file, or can I insert in image in?
color /?

image? impossibleWhy do people think Command Prompt can do all these magical THINGS?Quote from: feras on April 05, 2009, 04:47:39 AM
Hi everybody!

Any way to set a background to my batch file, or can I insert in image in?


MS-DOS and CMD are purely text based. You can CHANGE the text/background colour, but that's it.mm THANK you

Quote
Why do people think Command Prompt can do all these magical things?

Because they don't KNOW that is not true
3159.

Solve : How to cycle through numbers..??

Answer»

If %money% isn't assigned, then wouldn't set %money%=whatever bring an error because there was no variable name?I thought that in NT, the RECEIVING end of an anonymous pipe is launched in a separate child process, so any environment changes will not survive, so, BC_Programmer, how did you get the pipe method to work?



Quote from: Helpmeh on October 27, 2009, 04:36:17 PM

If %money% isn't assigned, then wouldn't set %money%=whatever bring an error because there was no variable name?

YES, I AGREE just the variable and not the contents of variable. I got no error messages, just the wrong answer. I did not use local variables, so the value was many times from the previous run. Finally I set the variable to zero at the beginning of the run and there after only zero appeared. No value was ever assigned to the variable with the pipe.

Strange: it looks like it should work.

The pipe in CMD, the COMMAND interpreter, does not work like UNIX and C.

Quote from: DarrenReeder on October 27, 2009, 08:47:14 AM
DOS is suupose to be the easier stuff
no, its not. there are programming limitations in DOS (cmd.exe) that makes it clumsy(if not impossible) to do certain things. eg floating point maths, arrays, ability for error control, date manipulation etc. If you want to learn programming, start with a real programming languageQuote from: Salmon Trout on October 27, 2009, 04:41:02 PM
I thought that in NT, the receiving end of an anonymous pipe is launched in a separate child process, so any environment changes will not survive, so, BC_Programmer, how did you get the pipe method to work?





Hmm, Not sure. Not sure how I had it working either, maybe it just appeared to work; I was messing about with the commandline seeing how I could force the contents of the file to be the stdin of set /p and I figured I do it with more, may as well give piping a shot. No idea how it worked, must have been a fluke and I had set a variable to the same value I was expecting (). I believe it's true though, that as far as the | is involved each program is given a inherited environment. (it was my understanding that they could inherit a handle to the same environment, and thus change the values within it... but I suppose cmd doesn't do that.

redirection works, and it's shorter, too.

What I did probably stems from when I used "ANSWER.com" to perform input queries in Pure DOS; since it was a program using the pipe to force input wasn't really that esoteric. (And of course the fact that the environment block was relatively UNCHANGED for the execution of any number of programs was a big plus).
3160.

Solve : Help me with this Batch File Code??

Answer»

mkdir c:\archive
xcopy c:\test c:\archive /d:10-26-09
compact /c c:\archive

This works but I need to know how to get it to look for FILES OLDER then two days. Cause the teacher wants it to be able to just grab anything older then 2 days without having to change the date everytime. Also this just compresses the folder. I need to know how it ZIPS the files that are placed into the folder. Can someone please help me?Oh and by the way. The folder that the files are in is c:\test and the batch file has to MAKE the folder c:\Archive and take the files older then 2 days from the folder c:\Test and zip them and move them to newly made folder c:\Archive. So please help me get this. Cause I been having serious issues.

3161.

Solve : Batch create crazy diretories from list.?

Answer»

It's a common thing on here... the classic error of the child/newbie/ignoramus: "This thing that looks complicated to me will look complicated to everybody."Quote

hiding it inside maze of folder is just too easy to break.

Your response to my request was very nice until I saw this. Now this takes all the fun out of it. So does that mean that now it is just a exercise in how to pull a prank on somebody? Create a maze of folders and move all of goat pictures to a folder in the bottom of the maze? Too easy to find. --sigh--

Still, is t really this easy? Is this batch? Looks like APL. I know all computers LANGUAGES, except APL. And this sure looks like APL to me!
Code: [Select]for /f "tokens=*" %a in ('dir/b/s/a-d') do @if %~za neq 0 echo %aHow does it work? what are the funny symbols for?I'm not very keen with the new Batch extensions introduced with the later NT command processors, but I'll see if I can break that down:

for /f "tokens=*" %a in ('dir/b/s/a-d')


performs the specified directory command, which returns a listing of all files in all folders within the current directory- note the /a-d part, which says not to include files with the directory attribute (no folders).

then, for each file found, it will execute:

Code: [Select]@if %~za neq 0 echo %a

I actually haven't a clue how it works, but the given comment "how to break garble" as well as the comparision tells us that it is comparing something to zero, only echoing it if it is not zero.

I might hazard a guess and say it's checking the filesize, which would mean that create files with anything more then a single byte of random characters all over the place, perhaps with filenames, and sizes the same as the "proper" files- maybe hundreds of them, all over the place, and only the person who created it knows the "real" file. Of course the idea is to waste their searchers time opening files that crash their image editor


It would confuse your basic user, but at the same time a "basic user" isn't looking for goat pictures, and just wants to know where the HECK he SAVED february's tax reports. OBVIOUSLY they would probably be puzzled why there are 500 "BESSIE.JPG" files, but probably would ignore them.

If somebody was "REALLY" looking for the files, they could simply search for them, and at the very worst open them until one succeeds, or EVEN better, look at the file times and open the earliest one.Quote from: BC_Programmer
then, for each file found, it will execute:

Code:

@if %~za neq 0 echo %a

for each filename found (%a in dir /b /a-d) in this and (/s) all subdirectories, if that file's size (%~za) is not zero (neq 0), echo the filename.
I'm trying to figure out how reno thinks that will break "garble"... garble, after all, would consume space...

Now- what if one was to literally store the "secret" files in the alternate data stream of the folders themselves?Quote from: BC_Programmer on April 07, 2009, 12:24:31 AM
I'm trying to figure out how reno thinks that will break "garble"... garble, after all, would consume space...

Now- what if one was to literally store the "secret" files in the alternate data stream of the folders themselves?

Or steganographically squirrel them away in goat images? Or did I mean goat them away in squirrel images? (Did you read about that racoon guy in Russia?)


yes yes- steganographically hide them in images that are then saved to alternate data streams! ha ha ha, it's perfect! even if they are found, all they can see is the pornographic images they were hidden in!
3162.

Solve : Printing MS-DOS to a USB printer?

Answer»

My mother has an OLD dos application and she wants to use it on her new NOTEBOOK with Windows XP SP3. DOS program works but it prints nothing on the USB printer now.

I read about trick with network sharing (NET USE LPT) but it doesn't work at us. I'd attached LPT1 to the pseudo-network printer but printer prints nothing still.

Can anyone some suggestions for me?If anyone is interested ..... There are several special utilities which had been designed for printing from a DOS program into Windows printer: DosPrint, DOSPRN, DOS2usb, PrintFil, DosPrinter etc.

Last WEEK I played with all of them.... Finally, I chose DOSPRN for my mom's computer. It is very simple, inexpensive and useful.

3163.

Solve : Make Directory using "variable"?

Answer»

Hi all

I run a daily batch file to make backups but do not want to overwrite the previous day's backup.

Answer for me is to let the batch file make a directory with "date" as directory, i.e.

set var=%date%

..... now var is set to today's date - OK so far ...

I now want to make a directory using "var" as the variable, i.e

md %var%

but this gives me a syntax error.

How do I make a directory in the batch file using "var"

Mike_KIf your system date format has forward SLASHES / as the separators you need to get 'em out because that character is illegal in a WINDOWS file or directory name.

e.g. replace with hyphens

Code: [Select]set var=%date:/=-%
or spaces

Code: [Select]set var=%date:/= %
or dots

Code: [Select]set var=%date:/=.%
(or whatever legal character or characters you like, put it or them to the right of the equals sign)

or nothing (nuke 'em)

Code: [Select]set var=%date:/=%
Thx Dias

I've used yur suggestion with a bit of other code ....

set today=%date:/=_%

echo off
echo THE CURRENT DATE IS (day/month/year) : %DATE%

mkdir "%today%"
cd "%today%"
echo .
echo CHECKING DESTINATION FOLDER IS TODAY'S MONTH/DATE
echo .
echo on (allows user to check destination folder by seeing the COMMAND prompt)
echo off
echo .
pause

Xcopy C:\Backup_\*.* /E/Y/I


As the days move on I will get a series of backup folders ...

07_04_2009
08_04_2009
09_04_2009 ..... etc.


Many thanks

Mike_K

3164.

Solve : MS-DOS batch file?

Answer»

Hi

I want your help I want to write a batch file to send STEP by step line of a text file which contains ASCII data to a motor stepper driver through the serial port, and then wait till the confirmation come back from the stepper driver "S" and so on till all the text file being sent.

Any query, I will supply more information, I have attached my EXCEL file which I want to convert it (CVS) file and sent it to the stepper driver.

Thanks for your helpQuote from: gimini75 on April 06, 2009, 10:19:21 AM

I have attached my EXCEL file

Where? In any case, batch is probably not the best way to do this. Do you mean real MS-DOS or Windows command?

Quote from: gimini75 on April 06, 2009, 10:19:21 AM
Hi

I want your help I want to write a batch file to send step by step line of a text file which contains ASCII data to a motor stepper driver through the serial port, and then wait till the confirmation come back from the stepper driver "S" and so on till all the text file being sent.

Any query, I will supply more information, I have attached my EXCEL file which I want to convert it (CVS) file and sent it to the stepper driver.

Thanks for your help

This is beyond the capabilities of Batch...Visual Basic Quote from: macdad- on April 06, 2009, 11:17:58 AM
This is beyond the capabilities of Batch...Visual Basic

Not in MS-DOS, unless you mean VB 1.0 for DOS. More likely have to be QBasic.
Depending upon if he means CMD or Dos itself.Quote from: macdad- on April 06, 2009, 11:31:22 AM
Depending upon if he means CMD or Dos itself.

The title says "MS-DOS batch file" and the post refers to the serial port, which says "MS-DOS" to me.
True...But still Batch is way out of this capability, QBasic would be the alternative.java sorry just being randomQuote from: squall_01 on April 06, 2009, 12:03:26 PM
java sorry just being random

java for MS-DOS?

http://ledos.sourceforge.net/

In place of it like I said its randomQuote from: squall_01 on April 06, 2009, 12:37:19 PM
In place of it like I said its random

And how eactly does it help the OP to post your random thoughts? Quote from: macdad- on April 06, 2009, 11:17:58 AM
This is beyond the capabilities of Batch...Visual Basic

I am humoring him that is all.Back in the dark ages I used some form of Microsoft BASIC to read and write from serial ports. Almost any version of MS Basic will read and write the COM ports.
But has he tested it user a TERMINAL?
Send out the codes manual, or cut and past?
There is all that baud rate, ODD or even or no parity, start and stop bits stuff to know about and set up.Quote from: Dias de verano on April 06, 2009, 11:11:24 AM
Where? In any case, batch is probably not the best way to do this. Do you mean real MS-DOS or Windows command?


Hi

I mean cmd under windows command not MS-DOS

Thanks
3165.

Solve : How can I get my DOS Computer to Boot Up??

Answer»

I have a DOS based computer that when it starts to BOOT up COMES up with a message asking for the BOOT diskette in Drive A: I don't have this disk. I think the computer forgot how to LOOK at the hard drive to boot up. Is there a work around to FIX this?I suspect you cmos battery is dead

In the past, I have gone into the cmos setup and reminded it of the hard drive, rebooting then worked.

You will need to replace the batteryThanks for replying gpl. After several attempts I was able to get to the BIOS and set it to boot off the hard drive.

Thanks,
Again
Well done

I still recommend you get a new cmos battery, otherwise this will happen every timeNice Catch gpl....

3166.

Solve : Using Evaluate in batch script.?

Answer»

XP Home.

With regard to Dias de VERANO's reply #4 here is there any way of amending the following script to prevent the runtime error "') was unexpected at this time"?

Evaluate formatnumber(22) returns the CORRECTLY formatted number when ENTERED at the command prompt.

CODE: [Select]
@echo off
cls

for /f %%1 in ('evaluate formatnumber(22)') do (
set number=%%1
)
echo %number%

Thanks.Code: [Select]
@echo off
cls

for /f %%1 in ('evaluate WScript.echo formatnumber(22)') do (
set number=%%1
)
echo %number%

oops... that doesn't work either.

Ahh- but I see from comparing it to Dias's script:

Code: [Select]
@echo off
cls

for /f %%1 in ('evaluate "formatnumber(22)"') do (
set number=%%1
)
echo %number%
add quotes around the expression.Yes, if you have a closing parenthesis in the dataset part of any FOR construct you need to protect it by quoting. This is a batch requirement, not a vbs thing.

Thank you both for the responses and for your patience with US learners.

3167.

Solve : Parsing string from file twice?

Answer»

Quote from: Helpmeh on October 23, 2009, 03:01:45 PM

I fiind it funny that the op has started to learn for loops before he or she has really learned the set command.

A lot of people don't so much "learn" to write code, it's more a case of copying and pasting.Very true, but some people learn that way. I first learned how to use for loops by studying Jacob's code in his AoA Local BETA. If only I still have that .ZIP archive. I was one of those weirdo's who learned by reading the documentation... the MS-DOS 6 help, to be precise.Quote from: BC_Programmer on October 24, 2009, 07:44:16 PM
I was one of those weirdo's who learned by reading the documentation... the MS-DOS 6 help, to be precise.
I am one of those wierdos who are too young and weren't even BORN when MS-DOS was around.

How much of that documentation would apply to the command processor in windows xp? and, Is it in digital format? and if the answer to the second question is yes, May I have a copy?ntcmds.chm is a lot better then the help reference included with MS-DOS. Quote from: BC_Programmer on October 24, 2009, 08:03:25 PM
ntcmds.chm is a lot better then the help reference included with MS-DOS.

%Windir%\Help\ntcmds.chm on XP but unfortunately, on many computers such as those made by Compaq/HP, they make it impossible to run ntcmds.chm separately from the help and support center, so you can't use the CHM search facility easily. I think running

hh ntcmds.chm

might do it though

AS for Vista, not included, so get it from an XP system or install disk or from e.g. Windows Server 2003 Adminpak from Microsoft.



Quote from: Helpmeh on October 24, 2009, 01:51:02 PM
Very true, but some people learn that way. I first learned how to use for loops by studying Jacob's code in his AoA Local BETA. If only I still have that .zip archive.

a LOT of people do the copy-and-paste part without doing the learning part though. Often they then say they have "written" a program, but are apparently quite oblivious of the most obvious errors and faults in the code thus produced. Errors that they would not have perpetrated had they actually thought about what the code does.
Salmon Trout
Thank you for your post. You are quite correct that %% vs. % is a little (lot?) foreign to me.
I have been trying to find a good DOS book but they seem to be quite hard to get compared to 10 years ago.

I will look at your code and give it a burl.

PS: It is amazing how many posts can appear in these threads when you turn your back for a moment.Quote from: Helpmeh on October 24, 2009, 07:54:42 PM
I am one of those wierdos who are too young and weren't even born when MS-DOS was around.
Sigh. I had a birthday on the weekend and I am too close to 50 to want to think about it. I had a FIDDLE with DOS 1.22 when it first came out and continued until 5.0. After that I switched to C, Pascal for a few years. I had a 10 year break but now I am back programming. I have written some C code but to complere the task I was given DOS will help. DOS is easier for file moving, deleting etc: rather than C.
Quote from: Helpmeh on October 24, 2009, 07:54:42 PM
How much of that documentation would apply to the command processor in windows xp? and, Is it in digital format? and if the answer to the second question is yes, May I have a copy?
A copy would be nice if possible.Quote from: Tigers! on October 26, 2009, 06:34:34 PM
DOS is easier for file moving, deleting etc: rather than C.A copy would be nice if possible.
if your task is just copying, moving deleting files, maybe. BUT if you want to go into serious programming, DOS is not the right tool. Computing has progressed SINCE your time. Nowadays, we don't just do moving, copying deleting of files.. there are a variety of tasks that people do such as grabbing stuffs from the internet and parsing HTML, XML, reading and parsing text inside PDFs, reading Word/Excel files and getting data, querying a database, telnetting, doing file transfers etc.... Quote from: Salmon Trout on October 23, 2009, 11:22:26 AM
try this if you want to actually use named variables

Code: [Select]@echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2,3,4* delims=\" %%a in (tiff.txt) do (
set full_line=\%%a\%%b\%%c\%%d
set file_name=%%d
echo Full line: !full_line!
echo File name: !file_name!
echo.
)

ST
I modified the code to move my files and clean up and it worked a treat. Thank you for that.
Further to your comments about learning more.
Looking at your code I am puzzled by your use of %%a in two apparently different situations. Firstly you are using it (so it seems to me) to step through the tokens on the line and then you are using it as an actual variable with a known value. How does DOS keep track?
You also assign the current value of %%a to the other variables %%b, %%c, %%d without explicitly assigning or setting them. Again how does DOS do that?
Without a good reference book I find it hard to know abour comamnds like !!. I have not yet found a site that mentions seemingly obscure commands like that. Do you have a good, available book or site?!var! Is not a command. It is the same as %var% except WITHIN a for loop if delayedexpansion is enabled. I didn't learn any of my reasonable knowledge from a book. Trial, error and looking a others' codes. Quote from: Tigers! on October 27, 2009, 06:24:05 PM
Looking at your code I am puzzled by your use of %%a in two apparently different situations. Firstly you are using it (so it seems to me) to step through the tokens on the line and then you are using it as an actual variable with a known value. How does DOS keep track?

You also assign the current value of %%a to the other variables %%b, %%c, %%d without explicitly assigning or setting them. Again how does DOS do that?

You need to read the FOR help. Open a command window and type FOR /?
3168.

Solve : handling spaces in dos?

Answer»

suppose there r three files in a DIRECTORY named "NEW folder" "new folder1" "new folder2"
how do i all the three using a single command(WILD CARDS or whatever)

Sorry, how do you do.....what?

3169.

Solve : FTP Stalls?

Answer»

Quote from: Spoiler on APRIL 03, 2009, 10:58:47 AM

Ok I want to ASK another question. From what I see so far your real goal is to copy a file from another machine to your machine right? Are both of these machines in the same network? Is the other machine running a FTP server? Is the folder called "Home" part of the other machines FTP server?

Are you planning on setting up a task for this or a menu or just run a BAT file?


Sorry for the LATE reply. Both are on different networks and the other machine is an FTP server. YES the home folder does exist in the ftp server. As I mentioned this works in an XP machine. My PLAN is to run the BAT file as a scheduled task weekly.
Quote from: gh0std0g74 on April 03, 2009, 07:00:56 PM
make sure that D is your root FTP folder. another way is to NOT specify the drive
Code: [Select]...
cd path1\path2
get file
...

It wasn't the root FTP folder. I changed it to the root and it hasn't made any difference.
3170.

Solve : silent bat file - Is it possible??

Answer»

Is there a command that can be used to run a batch file completely silent?yes, there is a way to run batch file in complete silence, but i won't post the code since it can be USE for "evil" doing.

so here is the code for running batch in half silence
Code: [Select]start /minQuote from: Reno on March 26, 2009, 09:25:48 PM

yes, there is a way to run batch file in complete silence, but i won't post the code since it can be use for "evil" doing.

so here is the code for running batch in half silence
Code: [Select]start /min

Well...in JUST batch, that's like half-silent...but if you convert it to an .exe...No one wonders why he WOULD NEED to run a batch file silently? Quote from: Carbon Dudeoxide on April 06, 2009, 09:58:23 PM
No one wonders why he would need to run a batch file silently?

heh, I was just thinking the same thing.


Also, "converting" a batch to EXE simply wraps the Batch file into the executable, which recreates the batch file and shellexecutes it.

I NEVER heard of such a thing I heard of were you can turn the code its self off.Quote from: joedavis on April 07, 2009, 01:52:09 PM
Why doesn't the output of the AT command come to the screen?



it did:

Quote from: joedavis on April 07, 2009, 01:52:09 PM
Added a new job with job ID = 1
3171.

Solve : Batch file to start a program on another computer?

Answer»

Hi guys.
Is there any way to start and shut down a program on ANOTHER computer on the same NETWORK with a batch file?
With a echo, like if the program is already running and i try to start it will echo "Already running" and the same if i shut down the program.

Best ragardtasklist /? should get you started.Hello, Apexi.
Welcome to CH.
The kind of thing you ask is sometimes used by an administrator to make changes on other computers from a central location. This is a good thing in a large area, such as a campus.
But it also can be used for harmful and even criminal acts. So we would like to know what the purpose will be for such a program.
Sorry for my LACK of English mates
There is no criminal acts, i just want to simplify my home network

I have a small network at home with 4 computers with poor bandwidth.
Every time i want to play a online game i have to connect with a remote CONTROL program (Radmin) to shut down all programs that use bandwidth, like torrent and FTP programs.
And i think it would be easier to just shut them down with a .bat file.

Well a friend to my wrote a Pike script file that works really good, but i want to see how a batch file would look like if you know what i mean.

Again, sorry for my lack of English.Here is a VIDEO where the administrator uses a script to do what is often called 'remote execution' of another computer on the same LAN.
http://www.howcast.com/videos/224614-Remote-Execution-and-Deployment-Of-Windows-Scripts

3172.

Solve : Automated Disk Cleanup?

Answer»

Hello Everyone!

I am trying to automate the disk CLEANUP process. I am wanting to use it under scheduled tasks. The idea is to be able to RUN a ".bat" file that will automatically add the entry to run disk cleanup. The only issue i am having is getting disk clean up to run unattended. It is important to have it run unattended because i work at a school and the student cannot be prompted for it. Can anyone please assist me?

Operating system being used: XP Pro SP3First:

Run cleanmgr /sageset=nn either from the run box or the cmd prompt where nn is any arbitrary number.

When the Disk Cleanup Settings window appears, check off the boxes you want disk cleanup to clean. Click OK to save settings.

Second:

To run unattended, run cleanmgr /sagerun=nn where nn is the same arbitrary number you used for sageset. Cleanmgr can be run from a batch file, windows script, the windows run box or the NT cmd prompt.

Disk cleanup run this way will clean all the disks on your system using the same settings. I'll leave it to your imagination to have different settings for each disk.

Good luck. I do appreciate your answer, but that is were the issue is. I really need to not have to check anything. It needs to be completely automated. Any other ideas? I probably should have been more clear. You need run sageset only once. Sagerun will CONTINUE to use the sageset settings until they are changed in which case it will use the new settings.

Note: the settings are stored in the registry, so they persist across system boots.

Perhaps this article will clear things up.

Thank you for your post. I understand the sageset and sagerun options. Do you know if there are registry entries for each checked item?


If there is i could probably export those keys, then export the sageset number. Then in my .bat file just add the entries to the new computer and then add the sageset number registry key. Then the last part of the .bat could be sagerun?

Does this make sense? Do you know if these keys exist? I will RESEARCH today for any.

Thank you for the assistance!

HoFLThe cleanmgr settings can be found in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches registry key and subkeys.

Backup the registry before you start. Messing with the registry can turn your PC into a brick!

Good luck. I know it can

I will post my results. Thanks again for the help!

3173.

Solve : batch script Adding Ip adresses to hosts file?

Answer»

Quote from: plm on April 07, 2009, 04:11:07 AM

Hi CDO

I am about to make sure that some hundred monitored servers can send their SNMP TRAPS to some newly added monitoring servers during an upgrade. I have no intention of any malicious acts. I am a virgin into SCRIPTING so i thought that the experts on batch scripting on this site might be able to get me started.

best regards plm
since you have spoken , here's a link for your reference.Quote from: gh0std0g74 on April 07, 2009, 06:13:29 AM
come on, what are talking about?

I am talking about network-administration software.I see this as an excuse to get post-count up.

Carbon SAID that the code that we could have given could have been used for malicous purposes. It may not be the OP, but LIKE he said, this is a public forum. ANYONE could see/use it.

OP, if you are a sys admin, then you should at least have enough knowledge of computers to make your own easy way to do what you first posted.@plm, reply #30 is what you need to get you started. check it out and see if it works for you.
Or, if you have no restriction to download gawk for windows(see my sig)
Code: [Select]C:\test>gawk "1" file1.txt file2.txt
10.20.30.40
50.60.70.80
1.2.3.4
5.6.7.8
3174.

Solve : Edit Ini File?

Answer»
If possible to edit a .txt or ini file in ? read line and data and edit them ...... Quote from: Deadly D on October 28, 2009, 01:54:39 AM
If possible to edit a .txt or ini file in ? read line and data and edit them ......

http://support.microsoft.com/kb/314081


If you are using XP Pro, you may edit the ini file. Hardly anyone edits the ini file. Only experienced Administrator should edit the ini file:

The purpose of the BOOT.ini file in Windows XP
View products that this article applies to.
This article was previously published under Q314081
For a Microsoft Windows 2000 version of this article, see 99743 (http://support.microsoft.com/kb/99743/ ) .

INTRODUCTIONThis article describes the purpose and contents of the Boot.ini file....This article describes the purpose and contents of the Boot.ini file.
MORE INFORMATIONWindows (specifically Ntldr) uses the Boot.ini file to determine which operating...Windows (specifically Ntldr) uses the Boot.ini file to determine which operating system options to display when the Startup program is running. By default, Boot.ini is not flagged as a read-only system file and generally does not require any manual modification.

If you must change the contents of this file, use the System tool in Control Panel:
Click Start button, click Control Panel, and then double-click System.
Click the Advanced tab, and then click Settings under Startup and Recovery.
Typically, the Boot.ini file contains the following data:
[boot loader]
timeout=30
default=scsi(0)disk(0)rdisk(0)partition(1)\winnt
[operating systems]
scsi(0)disk(0)rdisk(0)partition(1)\winnt = "Windows NT" /NODEBUG C:\ = "Previous Operating System on C:\"
The following list describes the meaning of the data in the Boot.ini file:
The "timeout" variable specifies how long Windows waits before choosing the default operating system.
The "default" variable specifies the default operating system.
The term "scsi(0)" means that the primary controller (that is frequently the only controller) is responsible for the device. If there are two SCSI controllers, and the disk is associated with the second controller, the controller is named "scsi(1)".

If the system uses IDE, enhanced IDE (EIDE), or Enhanced SMALL Device Interface (ESDI) drives, or if the system uses a SCSI adapter that does not have a built-in BIOS, replace "scsi" with "multi".
The term "disk(0)" refers to the SCSI logical unit (LUN) to use. This may be a separate disk, but most SCSI setups have only one LUN for each SCSI ID.
The term "rdisk(0)" refers to physical disk 1.
The term "partition(1)" is the partition on the first drive in the computer. If there are two partitions, partition C is partition(1) and partition D is partition(2).
A multi-boot parameter calls for checking the Winnt folder to start from a specified SCSI controller's disk and partition.
"/NODEBUG" specifies that no debugging information is being monitored. Debugging information is useful only for developers.
You can ADD the /SOS option to display driver names while the drivers are being loaded. By default, the OS Loader screen only shows progress dots.
"Previous Operating System on C:\" implies that the "previous operating system" is MS-DOS, because "C:\" is an MS-DOS path.
3175.

Solve : How to read target of .lnk file with command line?

Answer» strings.exe can be used to remove unwanted characters.
Code: [Select]C:\Documents and Settings\Administrator\Desktop>strings myshortcut.lnk

Strings v2.41
Copyright (C) 1999-2009 Mark Russinovich
Sysinternals - www.sysinternals.com

+00
#C:\
&:<s1
Program Files
PROGRA~1
&:<s
Novativa Streamster
NOVATI~1
&:=s
Streamster.exe
STREAM~1.EXE
C:\Program Files\Novativa Streamster\Streamster.exe
O*{
O*{
OK So I've got:
Code: [Select]@echo off
REM example
echo Set Shortcut=%1
echo set WshShell = WScript.CreateObject("WScript.Shell")>DecodeShortCut.vbs
echo set Lnk = WshShell.CreateShortcut(WScript.Arguments.Unnamed(0))>>DecodeShortCut.vbs
echo wscript.Echo Lnk.TargetPath>>DecodeShortCut.vbs
echo set vbscript=cscript //nologo DecodeShortCut.vbs
For /f "delims=" %%T in ( ' %vbscript% "%Shortcut%" ' ) do set target=%%T
del DecodeShortCut.vbs
Echo Shortcut %shortcut%
Echo Target "%target%">>target.txt And the output:
Code: [Select]C:\VB>ShortcutTarget.bat "C:/Documents and Settings/All Users/Desktop/Adobe Acro
bat 6.0 Professional.lnk"
Set Shortcut="C:/Documents and Settings/All Users/Desktop/Adobe Acrobat 6.0 Prof
essional.lnk"
set vbscript=cscript //nologo DecodeShortCut.vbs
C:\VB\DecodeShortCut.vbs(2, 1) WshShell.CreateShortcut: The shortcut PATHNAME mu
st end with .lnk or .url.

Shortcut
It seems like it would work if I could GET rid of the quotes around the path as it seems to want the last characters to be .lnk
So can I substring "C:/Documents and Settings/All Users/Desktop/Adobe Acrobat 6.0 Prof
essional.lnk"
to read C:/Documents and Settings/All Users/Desktop/Adobe Acrobat 6.0 Prof
essional.lnk
in my batch file? I need the quotes in the dos box since the path contains spaces?Quote from: nubia on April 06, 2009, 06:51:14 AM
OK So I've got:
Code: [Select]@echo off
REM example
echo Set Shortcut=%1
...

The line with REM example can be removed; it was just to show where an example was in the original batch.

There should not be an echo at the start of the next line! It should just be set Shortcut=[something]

Quote
I need the quotes in the dos box since the path contains spaces?

Yes, that is correct, and the solution is to PASS the shortcut name with quotes from the command line like this

Code: [Select]ShortcutTarget.bat "C:/Documents and Settings/All Users/Desktop/Adobe Acrobat 6.0 Professional.lnk"
But in the batch strip the quotes off using the tilde ("~") variable modifier: so use %~1 instead of %1 as you see below.



@echo off
Set Shortcut=%~1
echo set WshShell = WScript.CreateObject("WScript.Shell")>DecodeShortCut.vbs
echo set Lnk = WshShell.CreateShortcut(WScript.Arguments.Unnamed(0))>>DecodeShortCut.vbs
echo wscript.Echo Lnk.TargetPath>>DecodeShortCut.vbs
set vbscript=cscript //nologo DecodeShortCut.vbs
For /f "delims=" %%T in ( ' %vbscript% "%Shortcut%" ' ) do set target=%%T
del DecodeShortCut.vbs
Echo Shortcut %shortcut%
Echo Target %target%


I want to thank all of you who have helped me in this.
Dias especially. You have not only solved the problem you have taught me a lot, for which I am grateful.
This is a great site and I HOPE some day to be able to help others.
But it seems that I am way BEHIND every one and would like to learn more about Dos programming and vb script too.
I, from necessity, have jumped into the middle of this and think it would be a good idea to read a primer on the subjects. (Dos programming and vb script).
My best to all!
3176.

Solve : change key/value pairs in xml file from dos batch?

Answer»

Hi All,

One part of my dos bat file needs to parse an xml file LOOKING for a "key" then get the value from next line down, then ask user to change it, then edit/replace OLD value with new value.

Been at this for days now, looking for guidance, TIA.

Here is my lines in xml file:

111


need to prompt user showing number "111" then ask to replace 111.

I have tried MANY combos of find/findstr/for/if loops but no no avail.
Looking for fresh input and knowledge.

TIA, frustrated cpatte!Quote from: cpatte on October 29, 2009, 07:39:37 AM



Here is my lines in xml file:
<param name="license_ports">
<value>111</value>
</param>


We used commandline argument but can easily change to prompt:


C:\>type patte.bat
Code: [Select]@echo off

findstr /v "111" patte.txt > newpatte.txt

findstr /v "</param>" newpatte.txt > 2newpatte.txt

echo "<value>%1</value>" >> 2newpatte.txt

echo "</param>" >> 2newpatte.txt
OUTPUT:

C:\> patte.bat 113

C:\>type 2newpatte.txt
Here is my lines in xml file:

"113"
""

C:\>

I leave it to Cpatte to remove " (quotes) and add a prompt for user.

If Cpatte needs further help I will do the above.

Good luck

p.s. The Ghost will now tell US the Unix sed ( Stream Editor ) command can edit your file with one line of code. Sed is available for windows and will work inside a batch file.Quote from: cpatte on October 29, 2009, 07:39:37 AM


<param name="license_ports">
<value>111</value>
</param>



C:\> sed 's/111/113/' pattie.txt

OUTPUT:



113



C:\>Quote from: cpatte on October 29, 2009, 07:39:37 AM

<param name="license_ports">
<value>111</value>
</param>



C:\>type patsed.bat
Code: [Select]REM Use commandline argument: patsed.bat 113
@echo off
sed 's/111/%1/' pattie.txt
OUTPUT:

C:\>patsed.bat 113

C:\>REM Use commandline argument: patsed.bat 113



113



C:\>here's a vbscript.
Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "c:\test\file"
strInput = ""
strOutput = "c:\test\output.txt"
Set objFile = objFS.OpenTextFile(strFile,1)
Set objOutFile = objFS.CreateTextFile(strOutput,TRUE)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If InStr(strLine,"license_ports")> 0 Then
WScript.Echo "Enter new value: "
Do While Not WScript.StdIn.AtEndOfLine
strInput = strInput & WScript.StdIn.Read(1)
Loop
f=1
End If
If f=1 And InStr(strLine,"value") > 0 Then
strLine = "<value>"&strInput&"</value>"
f=0
End If
objOutFile.WriteLine(strLine)
Loop
objFile.Close
objOutFile.Close

output
Code: [Select]C:\test>more file
<param name="license_ports">
<value>111</value>
</param>
<param name="other">
<value>1888</value>
</param>


C:\test>cscript /nologo test.vbs
Enter new value:
876

C:\test>more output.txt
<param name="license_ports">
<value>876</value>
</param>
<param name="other">
<value>1888</value>
</param>

Quote from: billrich on October 29, 2009, 12:46:28 PM

Code: [Select]@echo off

findstr /v "111" patte.txt > newpatte.txt
findstr /v "</param>" newpatte.txt > 2newpatte.txt
echo "<value>%1</value>" >> 2newpatte.txt
echo "</param>" >> 2newpatte.txt
your method will not work when there are mulitiple tags, unless OP's XML file is just those 3 lines. Same to your sed solution.


Quote
p.s. The Ghost will now tell us the Unix sed ( Stream Editor ) command can edit your file with one line of code. Sed is available for windows and will work inside a batch file.
don't put words in my mouth. I would not even consider sed AT ALL. The ideal solution this is to use a proper XML parser. If not, use a language that can process multiline strings easily, have regex capabilities (although its not a must), and let me/others easily read and understand my code.
3177.

Solve : Batch file to move files and rename?

Answer»

Hey All,

I've got a tricky situation that I need some pro help on.

I have a directory with multiple folders and inside these folders are files with a .MOD extension.

I need to move all the files with the .MOD extension to another folder and rename the files as they are moved (I would prefer to copy in case any thing goes awry). I need to rename as they are copied due to the files having the same name.

I found that I can EASILY move files with the command prompt but with the added variables of renaming and multiple folders I'm not quote sure how to tackle this.

Any help is appreciated.

Thanks,
NathanWhat I would do is instead of SAY copying from point A to C is to add a step in between as a conversion cache to copy the files to this B location then use a wild card to change all extensions to the extension you want. Then have an instruction that will copy these from that B location to the destination you want being C. Then have a cleanup that deletes all data from location B so that the next data to go in is clean vs the prior data file extension conversion.

Maybe someone knows of an easier method, but I believe it will be a 3 location process where you have your origin of your data, a conversion location, and then the destination.Files never have the same name in the current directory. The OS will not allow two files with the same in the same directory. Try to name a file the same name as an existing file name in the same directory and report the error message.This may provide you a starting point. It will copy all files that end in mod extention below the current directory to different directory and rename to a number with mod extension.
Code: [Select]@echo off
setlocal enabledelayedexpansion
set i=0
for /F %%a in ('dir /B /S *.mod') do (
set /a i+=1
copy /v "%%a" d:\tmp\!i!.mod 'Change the path before you run this script
)
@billrich:
(not to argue or anything) i think he means to grab the .MOD files only (not the directories as well), and move them (while renaming). So this way there could be a case where 2 files have the same name in different directories and now they are going into one...Quote from: gregflowers on October 28, 2009, 02:14:38 PM

Code: [Select]@echo off
setlocal enabledelayedexpansion
set i=0
for /F %%a in ('dir /B /S *.mod') do (
set /a i+=1
copy /v "%%a" d:\tmp\!i!.mod
)

copy /v "%%a" d:\tmp\!i!.mod

That is a slick way to rename a file but does not weed out duplicate files. It simply gives a new name to the duplicate file. This is fine if only the file name is a duplicate.

Also, the for statement does not find .mod files when the path has spaces.

The following might work a little better? :

( I believe the "delims=" is necessary. )


C:\>type mod.bat
Code: [Select]@echo off
setlocal enabledelayedexpansion
cd \

set /a j=0
dir /B /s *.mod > mod.txt

for /f "delims=" %%a in (mod.txt) do (

set /a j+=1



copy "%%a" E:\tmp\!j!.mod
)
C:\>Bill I GAVE your second snippet a try but just got a hung command prompt window. I have also been tinkering with this process is vb script.

Anyone think a batch would be better than vbs or vice versa?

Thanks,
NathanQuote from: nslemmons on October 29, 2009, 05:27:12 PM
Bill I gave your second snippet a try but just got a hung command prompt window. I have also been tinkering with this process is vb script.

Anyone think a batch would be better than vbs or vice versa?


Nathan

Greg Flowers in post #3 gave the best answer. I merely tried to improve his answer slightly.

You will not get a better suggestion than what Greg provided.

Good Luck

p.s. I started the mod search from root because I don't know where your mod files are stored. You may remove cd \ and start the mod search whereever you please. The mod search from root will find the mod files whereever they are stored on any machine. ( Copy but don't delete any system mod files.) Quote from: nslemmons on October 29, 2009, 05:27:12 PM
Bill I gave your code a try but just got a hung command prompt window. Thanks,
Nathan

There is no hang with my code. It worked perfectly.
Here is the code and the Output:


C:\>type mod.bat
Code: [Select]@echo off
setlocal enabledelayedexpansion
cd \

set /a j=0
dir /B /s *.mod > mod.txt

for /f "delims=" %%a in (mod.txt) do (

set /a j+=1



copy "%%a" E:\tmp\!j!.mod
)


Output:

C:\> mod.bat
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.

C:\>e:

E:\>cd tmp

E:\tmp>dir
Volume in drive E is My Book
Volume Serial Number is 0850-D7C5

Directory of E:\tmp

10/28/2009 08:42 PM .
10/28/2009 08:42 PM ..
08/10/1998 05:05 AM 6,089 1.mod
08/10/1998 05:05 AM 35,749 10.mod
08/10/1998 05:05 AM 136,770 11.mod
04/14/2008 07:00 AM 2,080 12.mod
04/14/2008 07:00 AM 2,080 13.mod
08/10/1998 05:05 AM 692 2.mod
08/10/1998 05:05 AM 29,053 3.mod
08/10/1998 05:05 AM 105,878 4.mod
08/10/1998 05:05 AM 1,080 5.mod
08/10/1998 05:05 AM 35,749 6.mod
08/10/1998 05:05 AM 136,770 7.mod
08/10/1998 05:05 AM 6,089 8.mod
08/10/1998 05:05 AM 1,080 9.mod
13 File(s) 499,159 bytes
2 Dir(s) 139,471,556,608 bytes free

E:\tmp>

P.S. :
Greg's copy and rename line is an absolute jewel:

copy "%%a" E:\tmp\!j!.modQuote from: nslemmons on October 27, 2009, 06:06:02 PM
Hey All,

I've got a tricky situation that I need some pro help on.

I have a directory with multiple folders and inside these folders are files with a .MOD extension.

I need to move all the files with the .MOD extension to another folder and rename the files as they are moved (I would prefer to copy in case any thing goes awry). I need to rename as they are copied due to the files having the same name.

I found that I can easily move files with the command prompt but with the added variables of renaming and multiple folders I'm not quote sure how to tackle this.

Any help is appreciated.

Thanks,
Nathan

if you want to make sure there are no duplicates after you copy, you can give each file a unique random number, if allowed by your specs. Here's a vbscript you can use
Code: [Select]Set objFS=CreateObject("Scripting.FileSystemObject")
Randomize
strFolder = "c:\test"
strDestFolder = "c:\tmp\"
Set objFolder = objFS.GetFolder(strFolder)
Go (objFolder)
Sub Go(objDIR)
If objDIR <> "\System Volume Information" Then
For Each eFolder in objDIR.SubFolders
Go eFolder
Next
End If
For Each strFile In objDIR.Files
If objFS.GetExtensionName(strFile) = "mod" Then
name =strFile.Name
src = strFile.Path
rand=Int(1000000 * Rnd )
strName = objFS.GetBaseName(name)&rand
objFS.CopyFile src, strDestFolder&strName&".mod"
End If
Next
End Sub


save as test.vbs on command line
Code: [Select]c:\test> cscript /nologo test.vbs
Quote from: nslemmons on October 29, 2009, 05:27:12 PM

Anyone think a batch would be better than vbs or vice versa?

Thanks,
Nathan

I gave the vbs code by Ghost in post #9 a run and got no output the first time.

And got "permission denied" the second time.

Please post the VBS output here when you run the vbs code by Ghost in post #9.

Thanks

Quote from: billrich
Please post the VBS output here when you run the vbs code by Ghost in post #9.

since you insists..

Code: [Select]Set objFS=CreateObject("Scripting.FileSystemObject")
Randomize
strFolder = "c:\test"
strDestFolder = "c:\tmp\"
Set objFolder = objFS.GetFolder(strFolder)
Go (objFolder)
Sub Go(objDIR)
If objDIR <> "\System Volume Information" Then
For Each eFolder in objDIR.SubFolders
Go eFolder
Next
End If
For Each strFile In objDIR.Files
If objFS.GetExtensionName(strFile) = "mod" Then
name =strFile.Name
src = strFile.Path
rand=Int(1000000 * Rnd )
strName = objFS.GetBaseName(name)&rand
objFS.CopyFile src, strDestFolder&strName&".mod"
End If
Next
End Sub


save as test.vbs on command line
Code: [Select]C:\test>more test.vbs
Set objFS=CreateObject("Scripting.FileSystemObject")
Randomize
strFolder = "c:\test"
strDestFolder = "c:\tmp\"
Set objFolder = objFS.GetFolder(strFolder)
Go (objFolder)
Sub Go(objDIR)
If objDIR <> "\System Volume Information" Then
For Each eFolder in objDIR.SubFolders
Go eFolder
Next
End If
For Each strFile In objDIR.Files
If objFS.GetExtensionName(strFile) = "mod" Then
name =strFile.Name
src = strFile.Path
rand=Int(1000000 * Rnd )
strName = objFS.GetBaseName(name)&rand
objFS.CopyFile src, strDestFolder&strName&".mod"
End If
Next
End Sub

C:\test>dir /B /S
C:\test\.txt
C:\test\file
C:\test\output.txt
C:\test\test
C:\test\test.awk
C:\test\test.bat
C:\test\test.vbs
C:\test\test1
C:\test\test\aslfaa.mod
C:\test\test\sdlfjasf.mod
C:\test\test\test.asfklhasl
C:\test\test\test1
C:\test\test\test2.doc
C:\test\test1\123.mod
C:\test\test1\3231.mod

C:\test>dir c:\tmp
Volume in drive C has no label.
Volume Serial Number is 08AC-4F03

Directory of c:\tmp

10/30/2009 11:20 AM <DIR> .
10/30/2009 11:20 AM <DIR> ..
0 File(s) 0 bytes
2 Dir(s) 4,733,227,008 bytes free

C:\test>cscript /nologo test.vbs

C:\test>dir /B /S c:\tmp
c:\tmp\123176457.mod
c:\tmp\323114370.mod
c:\tmp\aslfaa254512.mod
c:\tmp\sdlfjasf277152.mod


it works for me. any discrepancies at your side is your own doing.Quote from: gh0std0g74 on October 29, 2009, 09:17:01 PM
since you insist. . .


"It works for me. any discrepancies at your side is your own doing."

Bill wrote:

The request on post #10 was for Nathan, the Original Poster to show the Output of the ghost VBS. We don't need more misleading information from the Ghost.

The batch file by Greg is much better.

You were told to send the files to another drive.

3178.

Solve : How to run stored procedure from dos command?

Answer»

Hi

I have to run couple of stored procedure on different databases.
I want to automate this process.

How can i run stored procedure from Dos COMMAND.

Regards
NehalMore information needed:

1.) What database type.

2.) What instructons do you want to execute.1) Its a SQL 2008 server databases.
2) Apply stored procedure to this databases. It could be new, amendments etc.
Quote from: NehalShah on OCTOBER 29, 2009, 06:12:48 AM

Hi

I have to run couple of stored procedure on different databases.
I want to automate this process.

How can i run stored procedure from Dos Command.

Regards
Nehal

no matter what database you are using, mysql, sql server , sybase etc, they COME with documentations. The first thing you should do is read them and see how to execute stored proc from the command line. Appriciate your promt reply.
I could find sqlcmd utility and will explore more on this.

Yes BASICALLY they are SQL statements i.e. *.sql file which i normally execute on batch of databases.

Comming to more specific requirement:
I have say couple of sql files (variable) which needs to be executed on batch of database (variable).
For sql files (variable) - i will keep this files in one local folder.
For database (variable) - i will keep the information about dbs and their server in one txt file.

Now i want to create one batch file i.e *.bat which will execute 'sqlcmd' picking up *.sql files from folder and database information from the txt file.

How can i achieve this
Information on this will be much appriciated.
3179.

Solve : for somthing = %%a?

Answer»

Hi All,
I have write batch to dir my folders in every DRIVE at pc. so far I write it in this way

@echo
cd\
c:
pause

dir c:\
@echo
pause
d:\
dir d:\
pause
e:\
dir e:\

I would like to find out any other way to dir all drives without naming this drives.

This might help you out.

Code: [Select]@echo off
for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| find /i "partition"') do (
dir %%i:
)

for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| find /i "dvd-rom"') do (
dir %%i:
)

for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| find /i "removeable"') do (
dir %%i:
)

For network drives use net use. You can use the same technique to filter the output.

Good luck.I think you spelled removable wrong. That may be an issue if the op tries to dir a flashdrive. Au contraire. I can't make this stuff up but Microsoft can.

Quote
C:\Temp>echo list volume | diskpart

Microsoft DiskPart version 5.1.3565

Copyright (C) 1999-2003 Microsoft Corporation.
On computer: LAPTOP

DISKPART>
Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
Volume 0 H DVD-ROM 0 B
Volume 1 C xpSystem NTFS Partition 17 GB Healthy System
Volume 2 D xpData NTFS Partition 2000 MB Healthy
Volume 3 E xpWare NTFS Partition 9 GB Healthy
Volume 4 F xpServices NTFS Partition 2000 MB Healthy
Volume 5 G xpMedia NTFS Partition 6001 MB Healthy
Volume 6 I KINGSTON FAT32 Removeable 954 MB

DISKPART>
C:\Temp>
Quote
I think you spelled removable wrong

Quote
I can't make this stuff up but Microsoft can.

This has been discussed in various places. The spelling seems to be a USA vs rest-of-the-world thing, rather like color/colour, center/centre, meter/metre etc; UK English dictionaries tend to give the spelling without a second 'e' but "removeable" is a fairly widespread variant spelling in the US. Merriam-Webster says:

3 : to be capable of being removed

— re·mov·abil·i·ty \-ˌmü-və-ˈbi-lə-tē\ noun

— re·mov·able also re·move·able \ri-ˈmü-və-bəl\ adjective

— re·mov·able·ness \-ˈmü-və-bəl-nəs\ noun

— re·mov·ably \-blē\ adverb

— re·mov·er noun Quote
The spelling seems to be a USA vs rest-of-the-world thing, rather like color/colour, center/centre, meter/metre etc

Could be, but the MS Word 2002 (XP) spell checker shows the correct spelling as removable. All in all it makes no difference. When dealing with data, you've got to handle it as it is.Quote from: Sidewinder on October 21, 2009, 04:50:38 PM
Au contraire. I can't make this stuff up but Microsoft can.

Hmm...is that a MS world-wide thing? I haven't noticed that and my regional settings are set to canada (I think). Quote from: Sidewinder on October 21, 2009, 12:35:53 PM
This might help you out.

Code: [Select]@echo off
for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| find /i "partition"') do (
dir %%i:
)

for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| find /i "dvd-rom"') do (
dir %%i:
)

for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| find /i "removeable"') do (
dir %%i:
)

For network drives use net use. You can use the same technique to filter the output.

Good luck.

thank you for your help .. and
I tried this but I get an error ? that :Application data "dir" is not recognized as an internal or external command, operable PROGRAM or batch command file.

Not sure what :Application data indicates. The code was designed to run from the prompt in a cmd window. Need more details. A copy and paste of the error message and what went before it would be most helpful.

Quote from: Sidewinder on October 26, 2009, 07:17:37 AM
Not sure what :Application data indicates. The code was designed to run from the prompt in a cmd window. Need more details. A copy and paste of the error message and what went before it would be most helpful.



here in below a copied of error massage



Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\ammmmm>@echo off
for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| find /i "partition"')
do (
%%i was unexpected at this time.
"Application Data"dir %%i:
'"Application Data"dir' is not recognized as an internal or external command,
operable program or batch file.
"Application Data")
'"Application Data")' is not recognized as an internal or external command,
operable program or batch file.

for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| find /i "dvd-rom"') d
o (
%%i was unexpected at this time.
"Application Data"dir %%i:
'"Application Data"dir' is not recognized as an internal or external command,
operable program or batch file.
"Application Data")
'"Application Data")' is not recognized as an internal or external command,
operable program or batch file.

for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| find /i "removeable"'
) do (
%%i was unexpected at this time.
"Application Data"dir %%i:
'"Application Data"dir' is not recognized as an internal or external command,
operable program or batch file.
"Application Data")
'"Application Data")' is not recognized as an internal or external command,
operable program or batch file.


thank youApplication data is a directory immediately below the username directory in documents and settings. I haven't a clue how that error message was generated.

From what I can tell, you are typing this in at the command prompt, (I read you wanted a batch file) in which case you should only use single % signs and the do instruction with at least the open paren should be on the same line as the if, otherwise the interpreter has no clue that the line is incomplete and requires more.

When typing at the command line:
Code: [Select]d:\wfc\testlib>for /f "tokens=3" %i in ('echo list volume ^| diskpart ^| find /i
"partition"') do (
More?

NOTE: It appears the for intruction is two lines long, however the interpreter sees the line as one logical line that requires completion.

I suggest you copy/paste the code I posted earlier into an editor, create a batch file, and then run run the batch file.

3180.

Solve : my favorites?

Answer»
Hi all,
I have a list of web SITES and I am TRYING to write batch file to add all this sites in this list to my favorites

or
enable me to BROWSE all web sites in this list. I have no IDEA where should I start. any HELP?
Hi all,
any idea with that?see here for example
3181.

Solve : add current date/time to filename?

Answer»

Hi there.

I have a batch file that runs a dts package against a txt file (extract.txt). The batch file runs 4 times a week. I used to just delete the extract file after the dts had finished but now I have to move the Extract file into a folder called E:\Extract\OLD.

my problem is that the extracts have to have the current DATE/time added to their file name, before they are put in the OLD folder, so that a collection of past extract files are stored in a folder, which can be viewed for reference. So what I need to do is rename the extract.txt so that the current date/time is added to the end of the file name:

eg extract.txt would RENAMED extract011120061534.txt (todays date and time)

and then move it into the old folder.

Is there a way of doing this within my current batch file so that the date/time is AUTOMATICALLY added to the file name.

Thanks in advance ps..im a novice at batch files, so please keep it simple if possibleDo you want to rename it with the current date and time? Or the date and timestamp of the file?

I am making the following assumptions: You are running Windows 2000 / XP / 2003 / Vista, your regional SETTINGS are U.S., English, and you want to use the preferred format of YYYYMMDDhhmm. Try:
Code: [Select]@echo off
setlocal
set hour=%time:~0,2%
if %hour% LSS 10 set hour=0%hour:~-1%
ren extract.txt extract%date:~-4%%date:~-10,2%%date:~-7,2%%hour%%time:~3,2%.txtIf you need a different format, post back and let us know.

If you just need to add the date to the filename (without time) it can be done in just 1 line of code.thanks I'll give that a try.

I get EMAIL an extract several times a week. Each time the extract has the same file name. Now I have to put the extracts in a folder called old, for referencing purposes I need the date/timestamp added to the filename, so that over a period of week, the "Oldfolder" will have files listed like thus:

extract110120061345.txt
extract110220061406.txtFour times a week? Then you don't need the time.

I suggest you change the standard for your history folder like this:
extract20061101.txt
extract20061102.txt

Namely, put the year first so at the end of the year
extract20061229.txt
extract20070102.txt
remain in order. Otherwise, all your Januarys will be together regardless of year.

Mac

This worked great!

Thanks.

Lorie

3182.

Solve : Create zip/rar file?

Answer»

Hi!
Is it possible to compress a folder/file to zip/rar from a batch file?
Thanks .


I allready have the answer:

makecab C:\set.txt C:\me.zip

Quote from: silversk8ter on April 07, 2009, 08:48:04 AM

I allready have the answer:

If you already have the answer, why did you ASK the QUESTION?
@dias, please enjoy your life more. little things like this shouldn't upset you at all.OK, let's assume the OP didn't mean "I already know how to do this".

You can use rar.exe which comes with WinRAR, or the command LINE program addon for Winzip. Which one were you thinking of?


Quote from: gh0std0g74 on April 07, 2009, 09:06:42 AM
@dias, please enjoy your life more. little things like this shouldn't upset you at all.

Wth?Quote from: Carbon Dudeoxide on April 07, 2009, 09:12:04 AM
Wth?

Ghostdog acting like he had 250000 posts instead of 25.
Quote from: Carbon Dudeoxide on April 07, 2009, 09:12:04 AM
Wth?
Quote from: Dias de verano
OK, let's assume the OP didn't mean "I already know how to do this".
get it?Quote from: Dias de verano on April 07, 2009, 09:13:59 AM
Ghostdog acting like he had 250000 posts instead of 25.

what has post count got to do with it?Quote from: gh0std0g74 on April 07, 2009, 09:22:43 AM
what has post count got to do with it?

Big post count=big man (me). Little post count=little boy (you).

Quote from: Dias de verano on April 07, 2009, 09:26:38 AM
Big post count=big man (me). Little post count=little boy (you).
you should know who i am. I just changed "O" to 0. Post count doesn't matter. Quote from: gh0std0g74 on April 07, 2009, 09:29:38 AM
you should know who i am. I just changed "O" to 0. Post count doesn't matter.

I know who you are.
Quote from: Dias de verano on April 07, 2009, 09:33:31 AM
I know who you are.

glad to hear that.You're the guy who turned the 'O' to '0'.He tried to make his girlfriend say OH! but what she actually said was zeroQuote from: Dias de verano on April 07, 2009, 08:57:05 AM
If you already have the answer, why did you ask the question?


Sorry about that..
Only after i post the problem i've MANAGE the answer.
I keep this post to someone with this kind of question..

Anyway, this way i can zip a file...what about zip an entire folder?
Anyone?

3183.

Solve : current folder name?

Answer»

i've got a problem again
how to get from :

c:\msdos

i need to asign current dir name to an variable in this case set a=msdos

cd command returns full adressCode: [Select]for %%A in ("%cd%") do set foldername=%%~nAC:\&GT;type salmon.bat
Code: [Select]@echo off

cd %homepath%

echo Current Directory = %CD%

for %%A in ("%cd%") do
(
set foldername=%%~nA

echo foldername = %foldername%

echo What does the for loop do?

echo "for %%A in ("%cd%") do set foldername=%%~nA"
)


OUTPUT:


C:\> salmon.bat
Current Directory = C:\Documents and Settings\Bill Richardson
foldername = Bill Richardson

thank you!I am not sure why BillHat wrote what he did.Quote from: Salmon Trout on October 30, 2009, 11:48:01 AM

I am not sure why BillHat wrote what he did.

TO:

All Hat and No Cattle:

In Texas we always show at least part of the Output. In Canada the OUTput is not required?

MANY new users do not know how to test code.

No need to test Code by the Ghost. The Ghost code never CHECKS out.

Show and Tell is required when we are new users from Texas.

Not everybody is as dumb as you think. I believe my code is SELF explanatory.
Quote from: Salmon Trout on October 30, 2009, 12:10:35 PM
Not everybody is as dumb as you think. I believe my code is self explanatory.


There are many new users who read these boards and a little extra show and tell helps.

Not knowing and stupid are not synonymous.

"Everybody is ignorant. Only on different subjects."
Will Rogers
3184.

Solve : Batch file help??

Answer»

I ALREADY POSTED this in the programming section by mistake, sorry. While I do appreciate Sidwinder's help, it just didn't work.

I haven't worked with batch files in years and this problem is really irritating me.

set var1=oldvalue

if not defined %var1% set var2=newvalue


Now I would think that because var1 is defined in the first line, that var2 wouldn't GET set, but it does.


if defined %var1% set var2=newvalue


There, I would think the value would be set, right? Nope.

Anyone have any ideas on what I'm doing WRONG?

I've tried:

if not exist
if exist
if not "%var1%"==""

Stumped....

I thought we solved this.

Lose the % signs around var1 in the not defined INSTRUCTION. The name of the variable is var1 not %var1%. Use the % signs when you want to extract the value of the variable. By using the % signs, the instruction resolves as if not defined oldvalue set var2=newvalue which causes var2 to be set because presumably oldvalue is not defined. You have turned oldvalue into a variable name not a variable value.

Code: [Select]C:\Temp>set var1=

C:\Temp>set var2=

C:\Temp>set var1=oldvalue

C:\Temp>if not defined var1 set var2=newvalue

C:\Temp>set var1
var1=oldvalue

C:\Temp>set var2
Environment variable var2 not defined

var1 is defined as having a value of oldvalue therefore var2 does not get set by the if not defined statement.

After 4 years in the army, you'd think I would have better attention to detail. The % sign was the problem. Thanks again sidewinder and I'm sorry for you having to explain it to me twice.

3185.

Solve : Need help for insert?

Answer»

I want to insert text in front of every lines. Is there anyone know how to do easy batch file?@echo off>newfile.txt
for /f "tokens=*" %%a in (oldfile.txt) do >>newfile.txt echo whatevertext%%asome other alternative
1) if you can DOWNLOAD stuffs to you COMP, get Gawk for WINDOWS(see my sig)
Code: [Select]C:\test>more file.txt
line 1
line 2

C:\test>gawk "{print \"whatever\"$0}" file.txt
whateverline 1
whateverline 2


2) vbscript
Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strFile= "C:\test\file.txt"
Set objFile = objFS.OpenTextFile(strFile,1)
Do Until objFile.AtEndOfStream
WScript.Echo "Whatever" & objFile.ReadLine
Loop
save as myscript.vbs and on command line:
Code: [Select]C:\test>cscript /nologo myscript.vbs
Whateverline 1
Whateverline 2


Quote from: Reno on April 07, 2009, 11:42:08 PM

@echo off>newfile.txt
for /f "tokens=*" %%a in (oldfile.txt) do >>newfile.txt echo whatevertext%%a

thanks for your help. It's work but if I have so many files in the DIRECTORY then I want to insert text for every files. Is there any other varibles that I have to put in?use another loop to go through all your files.Quote from: akeker on April 08, 2009, 12:57:59 AM
thanks for your help. It's work but if I have so many files in the directory then I want to insert text for every files. Is there any other varibles that I have to put in?

Code: [Select]@echo off

for %%$ in (*.txt) do (
echo Processing %%$ --^> new_%%$ 2>new_%%$
for /f "tokens=*" %%a in (%%$) do >>new_%%$ echo whatevertext%%a
)Quote from: Reno on April 08, 2009, 01:10:47 AM
Code: [Select]@echo off

for %%$ in (*.txt) do (
echo Processing %%$ --^> new_%%$ 2>new_%%$
for /f "tokens=*" %%a in (%%$) do >>new_%%$ echo whatevertext%%a
)

Thanks again. it's work very well indeed. I wish you have all you want.
3186.

Solve : FTP Filedownload?

Answer»

I am creating this BATCH file to download an file which is one day older to today's date and I am not able to execute the file because of some errors. can you please follow the below program and LET me know where I am going wrong.

Cd..
Cd..
A:
CD A:\DATA

@echo off
:: This section gets yesterday's date
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SETLOCAL ENABLEEXTENSIONS

:: Get current date in YYYYMMDD format
FOR /f "tokens=1-4 delims=/-. " %%G IN ('date /t') DO (call :FIXDATE %%G %%H %%I %%J)
goto :GETDATE

:FIXDATE
if "%1:~0,1%" GTR "9" shift
FOR /f "skip=1 tokens=2-4 delims=(-)" %%G IN ('echo.^|date') DO (
set %%G=%1&set %%H=%2&set %%I=%3)
goto :EOF

:GETDATE
:: Convert to MODIFIED Julian date
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
set /a dd=100%dd%%%100,MM=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2432046
set MJD=%j%

:: Subtract a day
set /a MJD=%MJD% - 1

:: Convert back to YYYYMMDD format
set /a a=%MJD%+2432045,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set datedsub=%yy%%mm%%dd%&set y=%yy%&set m=%mm%&set d=%dd%

echo %datedsub%

Please guide me in the right direction.Just as a note, don't use double colons for Remarks, instead use the REM command.why not ? i allways user them, you just cant use them in for loop

@gurusanjay

can you tell us what errors you get ? quick glance on your code:
if "%1:~0,1%" GTR "9" shift
- logic error eg.if "1" gtr "-2" (echo bigger) else echo smaller
- and you can't do substring on argument %1, you have to set it to variable first

if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
yy should be 4 digits, another logic error.

FOR /f "tokens=1-4 delims=/-. " %%G IN ('date /t') DO (call :FIXDATE %%G %%H %%I %%J)
it's better to use for .... ('echo %date:~-10%') do call::FIXDATE %%G %%H %%I

try this and let me know the result, the code is quite similar to your's, so i believe you will quickly understand the inner-working of the code:
Code: [Select]::source: http://en.wikipedia.org/wiki/Julian_day
@echo off & setlocal
if "%~1"=="" echo USAGE: %0 [interval] & goto:eof

for /f "skip=1 tokens=2-4 delims=(./-)" %%a in ('echo.^|date') do (
for /f "tokens=1-3 delims=./- " %%A in ('echo %date:~-10%') do (
set %%a=%%A& set %%b=%%B& set %%c=%%C
))
::echo Today :%yy%%mm%%dd%
set/a mm=1%mm%-100,dd=1%dd%-100

::jd
set/a a=(14-mm)/12, y=yy+4800-a, m=mm+12*a-3
set/a jd=dd+ (153*m+2)/5 + 365*y + y/4 - y/100 + y/400 - 32045
::date interval
set/a jd+=%~1

::gd
set/a s1=jd+68569, n=4*s1/146097, s2=s1-(146097*n+3)/4, i=4000*(s2+1)/1461001
set/a s3=s2-1461*i/4+31, q=80*s3/2447, s4=q/11, e=s3-2447*q/80
set/a yy=100*(n-49)+i+s4, mm=q+2-12*s4, dd=e, gd=yy*10000+mm*100+dd
::echo %1 :%gd%

echo %gd%
exit/b %gd%

sample output:
Code: [Select]C:\>jd -1
20090407

C:\>echo %errorlevel%
20090407if you are not restricted to choice of language, here's a Perl script example. It should make your life easier when dealing with things like date manipulation.
Code: [Select]use Net::FTP;
use Date::Calc qw( Today_and_Now Add_Delta_DHMS Month_to_Text );
my @date_time = Add_Delta_DHMS( Today_and_Now(), -1, 0, 0, 0 );
my $yest_month = substr(Month_to_Text($date_time[1]),0,3);
my $yest_day = $date_time[2];
my $file_to_get = "file.txt"; ## file to get.
$ftp = Net::FTP->new("127.0.0.1", Debug => 1) or die "Cannot connect to localhost: [emailprotected]";
$ftp->login("user",'password') or die "Cannot login ", $ftp->message;
$ftp->cwd("somedir");
my @listing = $ftp-> dir($file_to_get);
my @list = split / +/, $listing[0];
my $month = $list[5]; my $day = $list[6] ;
if (( $yest_day + 0 == $day + 0 ) && ( $yest_month == $month ) ) {
print "File is one day older than today...ok\n";
$ftp->get($file_to_get) or die "get failed ", $ftp->message;
}
$ftp->quit;

3187.

Solve : Batch script to check if last modified date is earlier than current day?

Answer»

I need to create a batch file to check the last modified date of a directory and if it's older than the current date i need to execute foo.com. Can someone assist?

Thanks.."foo.com" - what kind of a name is that? Just a generic name given since the name of the program isn't important. We could say I wanted to run 'KingKong.exe" OK. I just hate all that foo and bar stuff. Have done since my UNIX days.

.com means a DOS executable. But I guess again that's just an example.

What is your local date and time format setting?

Ya, I'm a LINUX admin

Anyways, I ended up piecing together some VB code and I think I am accomplishing what I want..

Dim fso, f, f1, fc
Set WshShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("c:\temp\")
Set fc = f.Files
For Each f1 in fc
If DateDiff("d", f1.DateLastModified, Now) &GT; 30 Then
WshShell.Run "bmail -s smtp1 -t [emailprotected] -f [emailprotected] -h -a Logging_Stopped"
End If
Next
Set fso = Nothing
Set f = Nothing
Set fc = Nothing Quote from: rmcc4444 on October 30, 2009, 12:18:43 PM

Ya, I'm a Linux admin
if you have been a linux admin AND if you can use *nix stuff on your WINDOWS environment, you can download GNU tools (SEE my SIG) and use them. After that i am sure you know how to use GNU find to search for files older than 30 days and delete them
3188.

Solve : Running multiple bat files at the same time, and then run a separate bat file.?

Answer»

Hi.
What I want to do is to run 2 bat files at the same time, and after these two bat files have finished (one of them finish earlier than the other), the third bat file is going to start.
What I have been doing until now is writing the commands from the third bat file into the first bat file, since the first bat file usally finish last, however that's not the case everytime, therefore I want to run these commands separately after the two bat files.
So, is this possible to do?

Modular programming is a software DESIGN technique that increases the extent to which software is composed from separate parts, called modules. Conceptually, modules represent a separation of concerns, and improve maintainability by enforcing logical boundaries between components. Modules are typically incorporated into the program through interfaces. A module interface expresses the elements that are provided and required by the module. The elements defined in the interface are detectable by other modules. The implementation contains the working code that corresponds to the elements DECLARED in the interface.

Languages that formally support the module concept include IBM/360 Assembler, COBOL, RPG and PL/1, Ada, D, F, Fortran, Haskell, OCaml, Pascal, ML, Modula-2, Erlang, Perl, PYTHON and Ruby. The IBM System i also uses Modules in RPG, COBOL and CL, when programming in the ILE environment. Modular programming can be performed even where the programming language lacks explicit syntactic features to support named modules.

Software tools can create modular code units from groups of components. Libraries of components BUILT from separately compiled modules can be combined into a whole by using a linker.


http://en.wikipedia.org/wiki/Modular_programming

p.s. We can use a main batch that CALLS other batch files. An exit /b from the sub batch will return the control to main batch. I would not call two batch files at the same time. The main batch might lose control of the flow.

Good luckexit /b made it. Thank you!

3189.

Solve : How do i check a file existency in a folder/directory?

Answer»

I WANT to CHECK the file existence in a file or FOLDER using DOSuse if EXIST. type if /? for more info.thanks got it.

3190.

Solve : existent directory?

Answer»

Dear

How can I ADD the EXISTING install path in a batch file
e.g.
program1 d:\install\ setup.ini
or
program 1 e: \install\setup.ini

MUST be LIKE program1 %???% setup.ini

3191.

Solve : how to asign dir result to the variable?

Answer»

how could i ASIGN dir result to the variable
this dosnot works

set /a result=dir /b /o:n

something like this dosnnot work either

set /a result=`dir /b /o:n`


C:\batextra>type sortdir.bat
Code: [Select]@echo off

setLocal EnableDelayedExpansion

dir /b /o:n *.bat > sortdir.txt
set /a c=0
for /f "delims=" %%a in (sortdir.txt) do (
set /a c+=1

set result!c!=%%a

echo result!c! = %%a

if !c! equ 10 goto eof
)

:eof
Output:


C:\batextra> sortdir.bat
result1 = 2line.bat
result2 = 2pdfdos.bat
result3 = A.bat
result4 = anecho.bat
result5 = ans.bat
result6 = AUTOEXEC.BAT
result7 = B.bat
result8 = Batch1.bat
result9 = batchname.bat
result10 = batexe.bat

C:\batextra>Quote from: animo on October 30, 2009, 03:15:11 AM

how could i asign dir result to the variable
this dosnot works

set /a result=dir /b /o:n

something like this dosnnot work either

set /a result=`dir /b /o:n`



i have a question for you. what do you want to do with those directory listing results? are you going to find files ? If say you have 10000 files under the directory, are you going to assign all these files a variable each ?? Quote from: animo on October 30, 2009, 03:15:11 AM
how could i asign dir result to the variable
this dosnot works

set /a result=dir /b /o:n

something like this dosnnot work either

set /a result=`dir /b /o:n`


We cannot assign all the filenames in a directory to one variable.

Usually only one line from a file to each variable.

Quote from: animo on October 30, 2009, 03:15:11 AM
how could i asign dir result to the variable
this dosnot works

set /a result=dir /b /o:n

something like this dosnnot work either

set /a result=`dir /b /o:n`



Where did Animo go? Ask a question and leave the room?

A variable is a storage location in RAM ( Random Access Memory ).
The amount of information we can store as a variable is limited ( usually one line from a text file with batch. ). When you shut down the information disappears.

A file is a memory location on the Hard Disk. The information remains after shut down.

Why would anyone expect to store all the information from a file in a variable location?

Your basic understanding of computers is not present.

Quote
Your basic understanding of computers is not present.

And some people can't separate a quote from their own reply.
Quote from: billrich on October 30, 2009, 04:21:45 PM


separate your quotes from your replies. Its annoying.

Quote
The amount of information we can store as a variable is limited ( usually one line from a text file with batch. ).
this has nothing to do with the question. Besides, the above is statement is wrong. The amount of information we can store in a variable is as equivalent to how much memory the computer system has. If you read a text file line by line and store into different variables for each line, you ARE basically using memory for the whole file. Get your PERSPECTIVE right. Also, there are functions in programming languages that reads the whole file into one big variable for the purpose of convenience, but ultimately, storing to many variables or one variable are both the same, they are both still using up memory.

Quote from: billrich
Your basic understanding of computers is not present.
the pot calling the kettle black.Quote from: gh0std0g74 on October 30, 2009, 06:39:13 PM
Pot and Kettle.

Animo(OP) wrote
"set /a result=`dir /b /o:n"`

Animo wrote:
"How could I assign dir result to the variable
The above does not work."

Bill wrote:
"We cannot assign all the filenames in a directory to
one variable with the for loop in Batch."

"Usually only one line from a file to each variable."

Bill Wrote:
The amount of information we can store as a variable is limited

( usually one line from a text file with batch. ).


Ghost wrote (Fed by BC) :

"This has nothing to do with the question."

Bill explains:

Read what Animo (OP) wrote above: Animo was trying to
assign all the files in a directory to one variable ( Result ).


Ghost wrote
"Besides, the above is statement is wrong.
The amount of information we can store in a variable is
equivalent to how much memory the computer system has. If you read a text file line by line and store into different variables for each line,
you ARE basically using memory for the whole file.

Also, there are functions in programming languages
that reads the whole file into one big variable for the purpose of convenience, but ultimately, storing to many variables or one variable are both the same, they are both still using up memory."

Bill wonders:

"What does the above have to do with Batch?"


No, Ghost you are wrong but you do not use Batch. The Batch for loop will allow only one line to be assigned to each variable.

So, what The Ghost writes has nothing to do with Animo's (OP) question.

GHOST, What is this about a Pot and Kettle?
This has come up before.
If you have a huge amount to information that you need to store, common practice is to put into some kind of database that can be stored as a file.
For practical reasons the number of variables you can have is limited.
If you use a FOR loop and the variables are part of the FOR structure, the limit is 26 variables.
A vailable should not be over 128 characters., says one reference. Some versions of ODS put a limit to the amount of memory that will be assigned to variables.

Yet if the OP wants to put the names of all the directories into some variables, he can do that. Maybe we don't know why, but it can be done.

Anyway, being rude to anyone has little value here. Quote from: billrich on October 30, 2009, 08:17:50 PM
Bill Wrote:
The amount of information we can store as a variable is limited
( usually one line from a text file with batch. ).
i say again. The amount of information you can store in a variable is unlimited, its only limited by the amount of physical RAM you have on your system!!! Whether or not DOS batch only read one line each time from a file is not the problem. I don't do batch , BUT i certainly know how to PROGRAM.
Code: [Select]@echo off
setlocal enabledelayedexpansion
set var=
for /f "delims=" %%a in (file) do (
set line=%%a
set var=!var! !line!
)
echo The file contents are: %var%
Since you are a so called batch guru, i assume you can see that %var% is one big variable, now containing all the lines of the file. Now, do you understand what this means???

Quote
GHOST, What is this about a Pot and Kettle?
now i have to give you english lessons? go figure out yourself.Quote from: gh0std0g74 on October 30, 2009, 08:56:50 PM
Code: [Select]@echo off
setlocal enabledelayedexpansion
set var=
for /f "delims=" %%a in (file) do (
set line=%%a
set var=!var! !line!
)
echo The file contents are: %var%

Since you are a so called batch guru , you can see
one big variable, now containing all the lines of the file.

Who wrote the code? Salmon Trout? Excellent. Did you provide a copy to Animo, the original Poster?

I never claimed to be a "Batch Guru." I had not used batch until I logged on here several months ago.

I'm 72. I don't work.

Where does Ghost work as a Programmer?

Ghost, read post #8 by Geek above.



Quote from: billrich on October 30, 2009, 09:20:18 PM
Who wrote the code? Salmon Trout? Excellent. Did you provide a copy to Animo, the original Poster?
anyone who knows how to write batch will know its a "standard way" to concatenate lines to one variable. Why should i provide a copy to OP? you are ridiculous. whether i want to provide solutions is my own business.

Quote
I never claimed to be a "Batch Guru." I had not used batch until I logged on here several months ago.
that's why i have written "so called batch guru". which implicitly means i am saying you are not.

Quote
I'm 72. I don't work.
that's why you have plenty of time trolling around.

Quote
Where does Ghost work as a Programmer?
what gives you the idea that i am a programmer? Does it mean i need to be a programmer in ORDER to program?


Quote from: animo on October 30, 2009, 03:15:11 AM
how could i asign dir result to the variable
this doesnot work

set /a result=dir /b /o:n

something like this does not work either

set /a result=`dir /b /o:n`


C:\batextra>type vardir.bat

Code: [Select]@echo off
REM code by unknown
setlocal enabledelayedexpansion
dir /b /o:n > dirvar.txt
set result=
for /f "delims=" %%a in (dirvar.txt) do (
set line=%%a
set result=!result! !line!
)

echo.
echo The directory contents assigned to result variable: %result%
OUTPUT:

C:\batextra>vardir.bat

The directory contents assigned to result variable: .uvwrap_v301.swf .uvwrap_v3
02.swf .uvwrap_v303.swf .uvwrap_v304.swf .uvwrap_v305.swf 2009.January.blanks 20
09.January.dotfile 2line.bat 2pdfdos.bat A.bat anecho.bat ans.bat AUTOEXEC.BAT B
.bat Batch1.bat batchname.bat batexe.bat batfile.bat bc.bat bcalc.bat beep.bat b
est.bat bill0910.bat bill0911.bat bill72.bat bill72.txt Blues.wma brost.bat BSET
Bver.bat caavsetupLog.txt caisslog.txt carbon.bat caret.bat caseyville.gif chan
gename.bat chkqo.bat choice.bat christmas.txt clear.bat clock.bat CONFIG.SYS cop
yfiles.bat copytxt.bat cosmic.bat count.txt countf.bat countword.bat dalete.bat
data.csv data06.txt date.txt datefile.bat datename.bat daydir.bat db.txt del3sec
.bat delnet.bat desk.bat dev.bat devstr.bat devtok.bat devtwo.bat devtxt.bat dev
u.bat Dias.bat digit.bat dir dirtree.bat dirvar.txt disklog.txt Divide.bat Docum
ents dostimer.bat drive.bat echprom.bat envvar.bat err.bat evaluate.bat evaluate
.vbs expand.bat extractfolder.bat field1.bat fiels1.bat fifty.bat file.bat file.
txt filelen.bat fileprop.bat filetovariable.bat finalstr.bat finalziplist.txt fi
nddir.bat findstring.bat findxfiles.bat FlashSavingPluginSetup.exe fold.bat fold
1 fold2 fold3 fold4 fold5 folder1 folder2 folder3 folder4 folder5 for.txt found.
bat FP.vbs g.bat game.bat gee.bat generatebat.bat ghost.bat gkata.bat go.bat goo
glemath.bat gotoline.bat h3.bat hello.bat helpme.bat helppetty.bat hi.bat his.ba
t hist hist.txt hmath.c homewk.txt homework3.bat hope.bat htmldrive.bat inc.bat
indent Instruct_for.txt jak.bat kaus.bat kay.bat Keeptime.bat lewbat.bat line.ba
t list_of_program_files.txt list2a.txt listone.txt log log.txt longshot.doc lw.b
at mac.bat macdir.bat main.bat map.bat map2.bat mapodd.bat match.bat math.bat ma
th2.bat menu.bat Menuhope.bat MenuHope.txt mon.bat mon.txt monnum.txt mpgname.ba
t MSDIR.bat msin.bat mwc.bat mydate.bat namedate.bat New Stories (Highway Blues)
.wma newbat.bat newname.bat nomodname.bat noperiod.txt notime.bat null old.bat o
ldfiles.bat orastr.bat outmenu.txt parsedate.bat particular.bat pdfdos.bat perio
d.bat period.txt PID_446170_AFIQ3Q4_RMOLA_MMY_160x600.sw f PID_446170_AFIQ3Q4_RMO
LA_MMY_160x600_Parent.swf pipe.txt playsong.bat pp.bat preloader.swf preloader01
.swf preloader02.swf progressbar.bat prtbat.bat psexec.exe quote.bat renamejpg.b
at renjpg.bat reno.bat replace.bat reploop.bat reveille.mp3 rmext.bat rmnum.bat
rmnum2.bat runany.bat safexp.zip save screenclean.swf sendfile.bat session.txt s
etvar.bat sfc SH_HISTO shakeit.gif show.bat show.txt shut.bat Sig.gif signal.txt
signature signature.htm sigop.gif sleep.exe sortdir.bat sortdir.txt sound.swf s
tartsig.bat str.bat str2.bat str3.txt strcat.bat striptime.bat strlen.bat succes
s.bat sumnum.bat TAPS.mp3 task.txt taskkill.exe tasklist.exe Tata.jpg tehthe.bat
temp.tmp temp1.txt tes3.bat tes4.bat test.bat test06.bat test07.bat test07.txt
test10.bat test18.bat testextract.bat testfilnam.txt TestLog.csv testnum.bat tes
tver19.bat testwhat.bat textsearch.bat timediff.bat timeinseconds.bat timest.bat
tips.txt tooktime.bat try.bat try06252009.bat try07182009.bat try07302009.bat t
wodate.bat uvwrap_v3.swf val.bat val20.bat valarie.bat vardir.bat vars.bat vartx
t.bat vbprop.bat verp.bat volis.bat wait1.bat wait10.bat wait2.bat wait5.bat wai
ttime.bat walkthetalk.swf wget.bat whatd.bat whatis.bat win.ini winder.bat windo
wsupdateagent30-x86.exe wmp.bat writetofile.bat x.txt x3.bat xc.bat xcc.bat xfif
ty.bat xinc.bat xlw.bat xmas.txt xplaysong.bat xsignature.htm xtry.bat xxsignatu
re.htm xxtestfl.bat xxx.txt xxxmenu.bat xxxxx.bat xy.bat y y.htm yourfile.bat z.
txt zeke.txt zip.bat zip2.bat ziplist.txt zzero.bat

C:\batextra>
3192.

Solve : start two batch files at the same time?

Answer»

How can i write a batch file which start two batch files at the same time?
Suppose i have two batch files abc.bat and def.bat. I want to write a batch file xyz.bat which will start abc.bat and def.bat at the same time.
I m eagerly waiting for help from you.
THANKS
devduttaaCode: [Select]start abc.bat
start def.bat
Quote from: Dias de verano on April 06, 2009, 03:27:44 AM

Code: [Select]start abc.bat
start def.bat

That doesn't work. It just opens the command PROMPT. If you want to open at the same time, try this.

Code: [Select]start cmd /c abc.bat
start cmd /c def.bat
That will open them up in their own window, and your first script can continue running (3 windows open).Quote from: Helpmeh on April 06, 2009, 05:56:40 AM
That doesn't work

Yes it does.

abc.bat

Code: [Select]@echo off
echo This is abc.bat
echo hello world

def.bat

Code: [Select]@echo off
echo This is def.bat
echo goodbye world

xyz.bat

Code: [Select]@echo off
Echo this is xyz.bat
start abc.bat
start def.bat

Result...
Wierd...that just opens 2 instances of the command prompt.Quote from: Helpmeh on April 07, 2009, 07:08:20 PM
Wierd...that just opens 2 instances of the command prompt.

Are abc.bat and def.bat in the same folder as def.bat? Do they contain any commands?
I say, you've got Consolas as your Command Prompt Font too.

It's a secret to everybody... Quote from: BC_Programmer on April 08, 2009, 12:35:27 AM
I say, you've got Consolas as your Command Prompt Font too.

It's a secret to everybody...

I cannot stand the default font! The raster one I mean. I used Lucida Console for a long while, toyed with Courier New for a bit, but Consolas is my favourite. I don't like WHITE text on black background either. I use Lucida Sans Typewriter in my text editor (Ultraedit32).
I switched to Consolas in VB6... courier new LOOKS like crap now!

I just wish the IDE had more options for colours and such; or DIFFERENT settings, such as bold and italic for it's syntax colouring. Oh well.

I had "Inconsolata" for a bit, but then I FOUND the free MS download of Consolas so I can use it on XP.

before I decided on consolas I toyed around with "proggy fonts":

http://www.proggyfonts.com/index.php?menu=download

for me, they are simply too small.

I'm not sure what the raster font really is, but if I had to guess I'd say it mapped to "system"...


which I might add was the default, unchangable font in Visual Basic version 1 through 3. I guess MS realized with 4 that the font blew hard.Quote from: Dias de verano on April 08, 2009, 12:23:13 AM
Are abc.bat and def.bat in the same folder as def.bat? Do they contain any commands?

Yes and yes.
3193.

Solve : how do I disallow a null entry from a user??

Answer»

Here is what I have :


@ echo off
cd\
cls
:start
cls
Set Unit=
Echo For funding purposes, we NEED to know what Unit you are from
Set /P Unit=Please enter unit ID
if /i %Unit% EQU null goto start
Echo %Unit%, %computername%, %date%, %time% &GT;>c:\test.txt
@ echo off
cd\
cls
:start
cls
Set Unit=
Echo For funding purposes, we need to know what Unit you are from
Set /P Unit=Please enter unit ID
if /i %Unit% EQU null goto start
if "%Unit%"=="" (
echo.
echo Please type something!
echo Please try again
echo.
goto start
)
Echo %Unit%, %computername%, %date%, %time% >>c:\test.txt


Does that work if a "return" or "enter" is pressed?Quote from: Aegis on April 07, 2009, 04:13:21 PM

Does that work if a "return" or "enter" is pressed?

It will ONLY work if Enter/Return is pressed. The set /p command requires either a string of characters terminated by Enter, or Enter alone. The "null string", represented by "", is another way of saying "Enter".
THANK you -- appreciate the explanation!That worked! Thanks for your help.
3194.

Solve : How do I ask for input from user and output to a file??

Answer»

I am looking to have a batch FILE run at logon which would ask a USER for his name and then OUTPUT it to a log file. I am unsure how to do so.Code: [Select]@echo off
set /p USERNAME="Please type your name and press Enter "
echo %date% %time% %username% >> login-log.txt
Nice, Dias -- I knew about the redirect, but didn't KNOW how to "set" it! That worked! thanks for your help.

3195.

Solve : Help with creating this Batch file?

Answer»

cd\
md c:\archive
xcopy /c c:\test c:\archive /d:10-26-09
compact /c c:\archive

This is the batch file I been working on. I have gotten it to do the oppisite I want it to do. Can someone help me get it to move only the files that are older 2 days. This command copys the files that are after the date above. So I need help getting them to copy and move the files that are older then two days WITHOUT PROVIDING the actual date. So please help me. If there is a way to zip the the files and move them that will help me greatly also. I want to show the teacher that this is possible cause he don't THINK it is possible that i will figure it out. But I cant do this alone. I not really versed in this style coding.I could not get the batch file to work.

I suggest nothing.

Good Luck



I could not get the batch file to work.

Bill

I do not suggest you use it.for deleting files older than blah date, that's one extremely slow batch script. Quote from: gh0std0g74 on November 01, 2009, 05:39:53 PM

for deleting files older than blah date, that's one extremely slow batch script.

So are you wanting to say the files will be too OLD by the time the batch gets to the end? LOL!
.

Which brings up an issue. Anytime you want to find something that is exactly N hours, days, months old, you will have a logical failure. From the time the program STARTS until it ends there may be a probability that some file will fall out of the time frame. This is an ERROR IN LOGIC.thanks for that joke, but no, its definitely not what i meant.
3196.

Solve : Creating a backup bat?

Answer»

Okay so we were doing dos for a while and there was issues with the machines that we were using so we have just stayed with linux for a while in my class. The thing is that I understand how to do it for the most part. I have xcopy S D /y /s /v But I also need it to be a desktop icon that will launch it when clicked, I am not at my machines so sadly not sure how much of this will work at all.Quote from: squall_01 on April 08, 2009, 12:12:04 PM

I have xcopy S D /y /s /v But I also need it to be a desktop icon that will launch it when clicked,

1. Put the commands you want to run, into a .bat or a .cmd file.

2. Save it to the desktop.

let me refrase that OH I suppose it is that easy. Okay so FORGET it then just wondered if I wasnt missing anything as well.Quote from: squall_01 on April 08, 2009, 12:22:15 PM
let me refrase that oh I suppose it is that easy. Okay so forget it then just wondered if I wasnt missing anything as well.

Yes it is that easy. If you do not want to put the actual batch on the desktop you can open Explorer, open the folder where the batch is located, right click the batch file icon and drag it out of Explorer ONTO the desktop, and when you let go the mouse button to drop it, you can choose "create shortcut here". You can rename the shortcut to anything you like and choose it a different icon if you want, but it will still point at the batch file, which (obviously) needs to remain in its location.

Probably what he was GOING to have us do. One thing I made the batch and told it to run with out ECHO off the thing is that I told it to copy one file and it starting coping a whole lot then it just like goes away from the disk.
3197.

Solve : Editting a BAT??

Answer» OKAY I done this batch files on a seperate machine and instead of going to them cause I would be going from ONE room to another, wondered what the code would be to change them I am USING 6.2 usally editted it in NOTEPAD but that isnt there.editah FORGOT that I did see that some were just never need it till know.
3198.

Solve : Logging a folders content size??

Answer»

I am looking for a way to log a folders content size such as C:\squid\var\cache for the Cache folder to log the size of the Cache storage. I was thinking I could use DIR and a switch to output the size, and Icant remember how I did it a long ways back. Would be nice to export the echo from the command for the folder size to a log file such as below, when executed from C:\squid\var\cache\

Fri 10/30/2009 at 11:43:01.28 Cache Folder is 124,656,576 bytes

The Cache folder has a bunch of sub DIRECTORIES that are stumping me on how to extract the size of the folder contents since DIR normally shows the local file content size, then the whole for the system below that, WITHOUT the properties of the local folder and sub-directories CONTAINED within it.


I know that the batch will be something like below where "DIR" will NEED to have something else done with it to get the output required. So looking for expert help where I am stumped. Maybe DIR isnt the way to handle this

@echo. %date% at %time% Cache Folder is >>CacheSize.log
DIR>>CacheSize.Log

[Saving space, attachment deleted by admin]Quote from: DaveLembke on October 30, 2009, 09:51:29 AM


DIR normally shows the local file content size, then the whole for the system below that, without the properties of the local folder and sub-directories contained within it.


Executed from a folder, Dir shows the names of any subfolders, and the names, dates and sizes of any files present in the folder, and the total size in bytes of the files in the folder only.

S:\Test\Batch>dir
Volume in drive S is USBHD
Volume Serial Number is 2C51-AA7F

Directory of S:\Test\Batch

26/09/2009 20:46 <DIR> .
26/09/2009 20:46 <DIR> ..
28/10/2009 21:02 <DIR> After 07-09-09
07/09/2009 17:13 <DIR> Older
15/05/2009 06:52 <DIR> EditVS
15/05/2009 06:56 <DIR> sst26
27/05/2009 17:56 116 Finder.bat
26/09/2009 20:46 44 getp2.bat
18/09/2009 16:51 217 isfolder.vbs
15/09/2009 17:48 46 ddf.vbs
09/05/2009 07:56 78 rarhelp.bat
25/05/2009 18:58 37 dequote.vbs
23/06/2009 19:34 245 Edit3
7 File(s) 783 bytes <-----------------------------------------
6 Dir(s) 146,969,190,400 bytes free


Are you saying you want to know the amount of data in each subfolder?

Hello...Yes I want to know how much total combined within local folder Cache and subfolders. I added a screenshot to show the subdirectory structure. I was thinking that maybe a DIR would have to be run against each sub directory and the sum of the files within it passed to a variable for every sub-folder/directory then the variables all added up at the end to give the lump sum of all data contained within Cache as the physical size of that folder and its sub-folders. (( But there has to be an easier method I am thinking ))

[Saving space, attachment deleted by admin]Are you able (permitted) to use the Sysinternals du utility?

http://live.sysinternals.com/du.exe

if so I will rough out a batch file


see my sig (GNU tools). Download and use them. It includes du command, plus others such as find (that is way better than Windows own), stat, etc you can use to show you sizes of files and folders. Of course, only if you are allowed to.Hello Salmon...sure I am sys admin and can run that. So if you can show a way to use DU and do that, that would be awesome. just type du c:\ for example on the command prompt. if you want, use a for loop to grab results. simple as that.Quote from: gh0std0g74 on October 31, 2009, 02:14:39 AM
just type du c:\ for example on the command prompt. if you want, use a for loop to grab results. simple as that.

Yes indeedy. Play around to get the syntax clear. Du /? to see help, where the various switches available are explained.

(I am using the Sysinternals du.exe)

Code below shows:

You can use the -q switch to prevent the Sysinternals copyright message (which, incidentally, if enabled echos to stderr not stdout)

I use quotes around folder names as good practice in case of spaces

Can pipe through Find "Size:" to get the line with file size

Comma separated file(s) size in bytes is 2nd token in that line

Remove commas from size to make suitable for set /a

Code: [Select]set dirname=C:\squid\var\cache
for /f "tokens=1-2" %%A in ('du -q "%dirname%" ^| find "Size:"') do set foldersize=%%B
set foldersize=%foldersize:,=%
i would recommend the GNU version since it has more capabilities and more or less works on a *nix with GNU as well.The Sysinternals version is simpler to manipulate (I have both) but as you say the GNU version is less limited (no commas in output. Another thing to consider might be DIRUSE from the NT Resource Kit

http://support.microsoft.com/kb/927229


Code: [Select]D:\Audio-DL>diruse /s "Amaral Discografia"

Size (b) Files Directory
23503006 1 AMARAL DISCOGRAFIA
45934192 13 AMARAL DISCOGRAFIA\Amaral
216104622 46 AMARAL DISCOGRAFIA\split-IOtest
73095739 13 AMARAL DISCOGRAFIA\Una Peque±a Parte del Mundo
358637559 73 SUB-TOTAL: AMARAL DISCOGRAFIA

358637559 73 TOTAL: AMARAL DISCOGRAFIA

D:\Audio-DL>diruse /s "Amaral Discografia" | find "TOTAL:"
358637559 73 SUB-TOTAL: AMARAL DISCOGRAFIA
358637559 73 TOTAL: AMARAL DISCOGRAFIA

D:\Audio-DL>diruse /s "Amaral Discografia" | find "TOTAL:" | find /V "SUB-TOTAL:"
358637559 73 TOTAL: AMARAL DISCOGRAFIA
Code: [Select]D:\Audio-DL>du -v "Amaral Discografia"

Du v1.31 - report directory disk usage
Copyright (C) 2005-2006 Mark Russinovich
Sysinternals - www.sysinternals.com

44,857 D:\Audio-DL\amaral discografia\Amaral
211,039 D:\Audio-DL\amaral discografia\split-IOtest
71,382 D:\Audio-DL\amaral discografia\Una Peque±a Parte del Mundo
350,231 D:\Audio-DL\amaral discografia

Totals:
Files: 73
Directories: 3
Size: 358,637,559 bytes
Size on disk: 358,637,559 bytes
Code: [Select]D:\Audio-DL>gnuDU -b -c "Amaral Discografia"
45934192 Amaral Discografia/Amaral
216104622 Amaral Discografia/split-IOtest
73095739 Amaral Discografia/Una Peque±a Parte del Mundo
358637559 Amaral Discografia
358637559 total

D:\Audio-DL>gnuDU -b -c "Amaral Discografia" | find "total"
358637559 total

Cool... Thanks for your help guys. Going to play with it and learn it.Quote from: Salmon Trout on October 31, 2009, 03:41:14 AM
The Sysinternals version is simpler to manipulate (I have both) but as you say the GNU version is less limited. Another thing to consider might be DIRUSE from the NT Resource Kit

http://support.microsoft.com/kb/927229


Code: [Select]D:\Audio-DL>diruse /s "Amaral Discografia"

Size (b) Files Directory
23503006 1 AMARAL DISCOGRAFIA
45934192 13 AMARAL DISCOGRAFIA\Amaral
216104622 46 AMARAL DISCOGRAFIA\split-IOtest
73095739 13 AMARAL DISCOGRAFIA\Una Peque±a Parte del Mundo
358637559 73 SUB-TOTAL: AMARAL DISCOGRAFIA

358637559 73 TOTAL: AMARAL DISCOGRAFIA

D:\Audio-DL>diruse /s "Amaral Discografia" | find "TOTAL:"
358637559 73 SUB-TOTAL: AMARAL DISCOGRAFIA
358637559 73 TOTAL: AMARAL DISCOGRAFIA

D:\Audio-DL>diruse /s "Amaral Discografia" | find "TOTAL:" | find /V "SUB-TOTAL:"
358637559 73 TOTAL: AMARAL DISCOGRAFIA
Code: [Select]D:\Audio-DL>du -v "Amaral Discografia"

Du v1.31 - report directory disk usage
Copyright (C) 2005-2006 Mark Russinovich
Sysinternals - www.sysinternals.com

44,857 D:\Audio-DL\amaral discografia\Amaral
211,039 D:\Audio-DL\amaral discografia\split-IOtest
71,382 D:\Audio-DL\amaral discografia\Una Peque±a Parte del Mundo
350,231 D:\Audio-DL\amaral discografia

Totals:
Files: 73
Directories: 3
Size: 358,637,559 bytes
Size on disk: 358,637,559 bytes
Code: [Select]D:\Audio-DL>gnuDU -b -c "Amaral Discografia"
45934192 Amaral Discografia/Amaral
216104622 Amaral Discografia/split-IOtest
73095739 Amaral Discografia/Una Peque±a Parte del Mundo
358637559 Amaral Discografia
358637559 total

D:\Audio-DL>gnuDU -b -c "Amaral Discografia" | find "total"
358637559 total


Quote from: Salmon Trout on October 30, 2009, 11:01:42 AM
Executed from a folder, Dir shows the names of any subfolders, and the names, dates and sizes of any filespresent in the folder, and the total size in bytes of the files in the folderonly.

S:\Test\Batch>dir
Volume in drive S is USBHD
Volume Serial Number is 2C51-AA7F

Directory of S:\Test\Batch

26/09/2009 20:46 <DIR> .
26/09/2009 20:46 <DIR> ..
28/10/2009 21:02 <DIR> After 07-09-09
07/09/2009 17:13 <DIR> Older
15/05/2009 06:52 <DIR> EditVS
15/05/2009 06:56 <DIR> sst26
27/05/2009 17:56 116 Finder.bat
26/09/2009 20:46 44 getp2.bat
18/09/2009 16:51 217 isfolder.vbs
15/09/2009 17:48 46 ddf.vbs
09/05/2009 07:56 78 rarhelp.bat
25/05/2009 18:58 37 dequote.vbs
23/06/2009 19:34 245 Edit3
7 File(s) 783 bytes <-----------------------------------------
6 Dir(s) 146,969,190,400 bytes free


Are you saying you want to know the amount of data in each subfolder?


I bolded the text that the op wants. It seems that even though salmon put it in red, no one noticed. that part only shows the size in the CURRENT directory. how about the rest of the directories? you have to individually go into each directory under s:\test\batch and get those sizes and add them up. Extra coding, extra brain cells killed. Quote from: gh0std0g74 on November 01, 2009, 05:13:10 PM
that part only shows the size in the current directory. how about the rest of the directories? you have to individually go into each directory under s:\test\batch and get those sizes and add them up. Extra coding, extra brain cells killed.

Yes, I wrote a huge batch that went one level deep doing just that before I remembered I had du and diruse. You can even use xcopy in list mode but that is probably just as tedious as using dir.
3199.

Solve : Find out how many times a Batch is used.?

Answer»

that works- I still like my alternate datastream IDEA, though. How about this:

Code: [Select]setlocal
for /f %%a in (countit) do set count=%%a
set /a count=count+1
echo %count% >countit

it saves the count in a file called countit and increments everytime its run
Quote from: uSlackr on April 07, 2009, 03:16:32 PM

How about this:

Code: [Select]setlocal
for /f %%a in (countit) do set count=%%a
set /a count=count+1
echo %count% >countit

it saves the count in a file called countit and increments everytime its run


Why use FOR, when if does the trick.

Simple:
Code: [Select]if not exist times.txt echo 0 > times.txt
set /p times=<times.txt
set /a times+=1
echo %times% > times.txtQuote from: HELPMEH on April 07, 2009, 06:55:33 PM
Why use FOR, when if does the trick.

Simple:
Code: [Select]if not exist times.txt echo 0 > times.txt
set /p times=<times.txt
set /a times+=1
echo %times% > times.txt

I suspect its 6 of one, but I didn't know you could do that with set /p. COOL tip.

Thx

\\uSlackrQuote from: uSlackr on April 07, 2009, 10:13:21 PM
I suspect its 6 of one, but I didn't know you could do that with set /p. Cool tip.

Thx

\\uSlackr

I think that set is the most usefull COMMAND (that I can use...)
3200.

Solve : USB token Security?

Answer»

hI ! to all i want to make USB token Security.

Like that i insert my PENDRIVE it DETECT but all other pen drive can't detect in my PC.

Because my friend load Trojan in my computer system via pendrive.

it is possible ? Pls Help me...
Here are some of the USB security TOKENS available....... Just have a LOOK at them

http://www.eyenetwatch.com/USB_hard_drive/security_tokens.htm
i don't want to purchase any thing..

i want make pen drive like this.....