Results 1 to 15 of 15

Thread: need some DOS help

  1. #1
    Senior Member grundy's Avatar
    Join Date
    Dec 2000
    Location
    CA
    Posts
    1,308

    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!

  2. #2
    Junior Member MadDoctor's Avatar
    Join Date
    Apr 2001
    Location
    Looks dark
    Posts
    0
    Norm know all about this stuff. Hang in there. He'll be around in a bit.
    People will forget what you said... and people will forget what you did... but people will never forget how you made them feel.

  3. #3
    Senior Member grundy's Avatar
    Join Date
    Dec 2000
    Location
    CA
    Posts
    1,308
    Quote Originally Posted by MadDoctor
    Norm know all about this stuff. Hang in there. He'll be around in a bit.
    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..."

    Norm?

  4. #4
    Elite Member Norm's Avatar
    Join Date
    Mar 2001
    Posts
    14,133
    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
    Last edited by Norm; 06-23-05 at 07:55 AM.

  5. #5
    Senior Member grundy's Avatar
    Join Date
    Dec 2000
    Location
    CA
    Posts
    1,308
    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!

  6. #6
    SG Enthusiast
    Join Date
    Jan 2001
    Location
    DC
    Posts
    4,717
    Does DOS support arrays?
    anything is possible - nothing is free


    Quote Originally Posted by Blisster
    It *would* be brokeback bay if I in fact went and hung out with Skye and co (did I mention he is teh hotness?)

  7. #7
    Senior Member grundy's Avatar
    Join Date
    Dec 2000
    Location
    CA
    Posts
    1,308
    Quote Originally Posted by cyberskye
    Does DOS support arrays?
    not sure about that. good suggestion though, I'll look into that tomorrow.

  8. #8
    Senior Member grundy's Avatar
    Join Date
    Dec 2000
    Location
    CA
    Posts
    1,308
    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!

  9. #9
    SG Enthusiast
    Join Date
    Jan 2001
    Location
    DC
    Posts
    4,717
    I don't use DOS so can't really help you.

    - this is silly-easy on a unix system (shell or perl script)
    anything is possible - nothing is free


    Quote Originally Posted by Blisster
    It *would* be brokeback bay if I in fact went and hung out with Skye and co (did I mention he is teh hotness?)

  10. #10
    Senior Member grundy's Avatar
    Join Date
    Dec 2000
    Location
    CA
    Posts
    1,308
    Quote Originally Posted by cyberskye
    this is silly-easy on a unix system (shell or perl script)
    need this for a windows-only app

  11. #11
    Elite Member Norm's Avatar
    Join Date
    Mar 2001
    Posts
    14,133
    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.
    Last edited by Norm; 06-26-05 at 11:49 AM.

  12. #12
    Quote Originally Posted by grundy
    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 like dos.

    Specs on the run command function of the PC are required? just trying to help.

  13. #13
    Senior Member grundy's Avatar
    Join Date
    Dec 2000
    Location
    CA
    Posts
    1,308
    Quote Originally Posted by Norm
    For some reason when used in a batch file there needs to be 2 % signs before each variableA
    holy cow, that works! Norm, I sincereley appreciate the help. I don't think I would have figured that out on my own!

  14. #14
    Second Most EVIL YARDofSTUF's Avatar
    Join Date
    Nov 2000
    Location
    USA
    Posts
    69,987
    Quote Originally Posted by grundy
    holy cow, that works! Norm, I sincereley appreciate the help. I don't think I would have figured that out on my own!


    Thats why he is the "DOS Master!"

  15. #15
    Elite Member Norm's Avatar
    Join Date
    Mar 2001
    Posts
    14,133
    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •