need some DOS help
need some DOS help
hello,
I'm trying to set up a batch file which will monitor the number of files in particular directory. I'd like to run this on a scheduled basis, then write the time, date, and number of files into a log file.
This much I have working, with one issue, which is that I can't figure out how to write all of the information onto a single line. Ideally, I'd like to write out in single lines in the format [date],[time],[#file] in order to create a csv.
Does anybody know how to append the results of multiple dos commands to a single line of output?
Alternately, is it possible in dos to set a variable to an evaluated, non-numeric expression? If I could set num_files=(dir "*.net" |find "File(s)") and end up with the variable num_files equal to the result of dir "*.net" |find "File(s)" I'd be in business...
any ideas? thanks for looking!
I'm trying to set up a batch file which will monitor the number of files in particular directory. I'd like to run this on a scheduled basis, then write the time, date, and number of files into a log file.
This much I have working, with one issue, which is that I can't figure out how to write all of the information onto a single line. Ideally, I'd like to write out in single lines in the format [date],[time],[#file] in order to create a csv.
Does anybody know how to append the results of multiple dos commands to a single line of output?
Alternately, is it possible in dos to set a variable to an evaluated, non-numeric expression? If I could set num_files=(dir "*.net" |find "File(s)") and end up with the variable num_files equal to the result of dir "*.net" |find "File(s)" I'd be in business...
any ideas? thanks for looking!
that's funny, I haven't looked at this forum in probably two years. today I spent an hour or so searching through dos documentation and thinking "who the heck knows about this stuff... I remember there was this guy Norm on Speedguide..."MadDoctor wrote:Norm know all about this stuff. Hang in there. He'll be around in a bit.
Norm?
set hour=%time:~0,2%
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%_%hour%_%time:~3,2%_%time:~6,2%
echo %folder%>onelineoftext.txt
Cramped for time, so here's a quick example to work with.
Notice there are two vatiables HOUR and FOLDER. In the 3rd line FOLDER adds the date and HOUR to become ONE variable named FOLDER
In the last line FOLDER is echoed to a file and prints ONE line.
All you need to do for your batch file is create a third variable, adding the #files as a variable.
I'll keep an eye on the thread to see that you have understood. Working till 10pm or so tonight, on my way to work now.
Even simpler, to help understand what I mean.
set first=norm
set second=earl
set third=%first%_%second%_steadman
echo %third%>onelineoftext.txt
Will output norm_earl_steadman to a file named onelineoftext.txt
Good luck
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%_%hour%_%time:~3,2%_%time:~6,2%
echo %folder%>onelineoftext.txt
Cramped for time, so here's a quick example to work with.
Notice there are two vatiables HOUR and FOLDER. In the 3rd line FOLDER adds the date and HOUR to become ONE variable named FOLDER
In the last line FOLDER is echoed to a file and prints ONE line.
All you need to do for your batch file is create a third variable, adding the #files as a variable.
I'll keep an eye on the thread to see that you have understood. Working till 10pm or so tonight, on my way to work now.
Even simpler, to help understand what I mean.
set first=norm
set second=earl
set third=%first%_%second%_steadman
echo %third%>onelineoftext.txt
Will output norm_earl_steadman to a file named onelineoftext.txt
Good luck
Thanks Norm,
I'm aware of the ability to concatenate multiple variables onto a single line of output.
What I can't figure out how to do is to set a variable to anything other than a literal string, or an evaluated mathematical expression.
Again, I want to set a variable equal to the number of files in a directory. For example:
C:\Documents and Settings\solomonw\My Documents>dir "*.doc" | find "File(s)"
13 File(s) 1,184,256 bytes
I want to set a variable equal to the output line here. Clearly, I'll need to parse out the '13', but there appears to be adequate documentation to help me with that.
The only thing that I can think of is an if statement, but the number of files may vary between about 0-100, so that would be less than elegant.
Is it possible to do this?
thanks again for the help!
I'm aware of the ability to concatenate multiple variables onto a single line of output.
What I can't figure out how to do is to set a variable to anything other than a literal string, or an evaluated mathematical expression.
Again, I want to set a variable equal to the number of files in a directory. For example:
C:\Documents and Settings\solomonw\My Documents>dir "*.doc" | find "File(s)"
13 File(s) 1,184,256 bytes
I want to set a variable equal to the output line here. Clearly, I'll need to parse out the '13', but there appears to be adequate documentation to help me with that.
The only thing that I can think of is an if statement, but the number of files may vary between about 0-100, so that would be less than elegant.
Is it possible to do this?
thanks again for the help!
hey hey y'all, progress
I cd to the correct directory, count the number of files, and write this out to a file:
dir "*.net" |find "File(s)" > C:\test\LicCount.txt
this writes out in the format '1 File(s) 0 bytes'
then I parse out the number, and write out date, time, number:
for /F "tokens=1" %A in (C:\test\LicCount.txt) do @echo %time%,%date%,%A>>C:\test\LicLog.txt
the problem is that, while the above command succeeds if run from a command prompt, it fails as a batch script. I've tried as both a .bat and .cmd. Any idea why it is failing or how I can fix it?
thanks again for the help!
I cd to the correct directory, count the number of files, and write this out to a file:
dir "*.net" |find "File(s)" > C:\test\LicCount.txt
this writes out in the format '1 File(s) 0 bytes'
then I parse out the number, and write out date, time, number:
for /F "tokens=1" %A in (C:\test\LicCount.txt) do @echo %time%,%date%,%A>>C:\test\LicLog.txt
the problem is that, while the above command succeeds if run from a command prompt, it fails as a batch script. I've tried as both a .bat and .cmd. Any idea why it is failing or how I can fix it?
thanks again for the help!
Frankly, it was beyond me. I hate that. So the rest is history.
Change
for /F "tokens=1" %A in (C:\test\LicCount.txt) do @echo %time%,%date%,%A>>C:\test\LicLog.txt
to
for /F "tokens=1" %%A in (C:\test\LicCount.txt) do @echo %time%,%date%,%%A>>C:\test\LicLog.txt
For some reason when used in a batch file there needs to be 2 % signs before each variableA
Now we both know, thanks it'll come in handy.
Change
for /F "tokens=1" %A in (C:\test\LicCount.txt) do @echo %time%,%date%,%A>>C:\test\LicLog.txt
to
for /F "tokens=1" %%A in (C:\test\LicCount.txt) do @echo %time%,%date%,%%A>>C:\test\LicLog.txt
For some reason when used in a batch file there needs to be 2 % signs before each variableA
Now we both know, thanks it'll come in handy.
- Mad_Haggis
- Senior Member
- Posts: 4128
- Joined: Sun Mar 07, 2004 12:00 pm
I like dos.grundy wrote:hello,
I'm trying to set up a batch file which will monitor the number of files in particular directory. I'd like to run this on a scheduled basis, then write the time, date, and number of files into a log file.
This much I have working, with one issue, which is that I can't figure out how to write all of the information onto a single line. Ideally, I'd like to write out in single lines in the format [date],[time],[#file] in order to create a csv.
Does anybody know how to append the results of multiple dos commands to a single line of output?
Alternately, is it possible in dos to set a variable to an evaluated, non-numeric expression? If I could set num_files=(dir "*.net" |find "File(s)") and end up with the variable num_files equal to the result of dir "*.net" |find "File(s)" I'd be in business...
any ideas? thanks for looking!
Specs on the run command function of the PC are required? just trying to help.
BEER
- YARDofSTUF
- Posts: 70006
- Joined: Sat Nov 11, 2000 12:00 am
- Location: USA
Glad to be of assistance.
Once I saw the actual line of code you were using I did some playing and testing (to no avail) It worked on the commandline, but not in a batch file.
Then I had a faint memory of someone telling me to RTFM lol (inside joke - me)
In the XP help files, in the commandline reference section under the FOR command.
Deep in the page.......
"To use FOR in a batch file, use the following syntax:
for %%variable in (set) do command [CommandLineOptions]"
All is well and we both learned something. Actually, I've never used the FOR command in all the batch scripts I've written. It's nice to know how it works and I'll probably be using it in future.
Thank you.
Norm
Once I saw the actual line of code you were using I did some playing and testing (to no avail) It worked on the commandline, but not in a batch file.
Then I had a faint memory of someone telling me to RTFM lol (inside joke - me)
In the XP help files, in the commandline reference section under the FOR command.
Deep in the page.......
"To use FOR in a batch file, use the following syntax:
for %%variable in (set) do command [CommandLineOptions]"
All is well and we both learned something. Actually, I've never used the FOR command in all the batch scripts I've written. It's nice to know how it works and I'll probably be using it in future.
Thank you.
Norm