Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

date stamping files in dos batch jobs

  • 27-12-2001 12:50pm
    #1
    Registered Users, Registered Users 2 Posts: 2,894 ✭✭✭


    Hey guys,

    I've written a little batch job to give me a directory listing and piped out the results to a file, say results.txt for arguments sake. This runs each day. What would be great would be to date stamp the files and then archive them off to another directory so I'd have for today 27122001results.txt

    I've messed about with the type command, piping etc etc but I cant find an easy why to do it using solely dos commands.

    Does anyone have any suggestions or have done something similar themselves.

    Cheers,
    Tin


Comments

  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    touch.exe ?

    not sure why you would want to change the date though? If the file was altered wouldn't the archive bit be set?


  • Registered Users, Registered Users 2 Posts: 391 ✭✭dragonkin


    Thanks Hobbes gave me a good excuse to start coding!
    Whipped together this little proggie for you hopefully it will do what you want.
    "timestamp" (with no arguments) returns 31122001.. not much use I know.

    "timestamp filename" renames filename to 31122001filename (or whatever)

    Hopefully that is of some use to you email me with problems

    DK


  • Registered Users, Registered Users 2 Posts: 391 ✭✭dragonkin


    I don't know why but the attachment didn't work the last time..
    It's my first time trying an attachment so maybe I'm just not seeing it ??

    www.esatclear.ie/~thelair/timestamp.zip (if all else fails)


  • Registered Users, Registered Users 2 Posts: 2,894 ✭✭✭TinCool


    Thanks dragonkin. I actually found a similar exe called now.exe which does exactly the same thing as yours. Thanks for your efforts though, how did you code that btw ?


  • Registered Users, Registered Users 2 Posts: 391 ✭✭dragonkin


    Ohh just a bit of simple C/C++
    using the time.h header file

    Only about 20 lines of code in all


    DK


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    I misread what he wanted. I could probably do it in one line, two tops. :) Do I win a prize?

    W2K command allows you create a date variable.

    I think it's something like $~d1 or something like that (not confirmed!). I'd need to read the help screen again.

    so it would be something like.

    ren %1 %~d1%1

    If your using NT you could use the output from the DATE command via another batch file and use the SET command to pull out the bits you want to create the date from.

    eg.

    ENTER.TXT
    put in one blank line (press enter once)


    A.BAT
    DATE < ENTER.TXT | find "Current" > TEMP.BAT
    call TEMP


    CURRENT.BAT

    set CDATE=%5


    So when you run A.BAT it will write the following line to temp.bat

    Current date is Sat 05/01/2002

    Then when you run temp.bat it will run CURRENT.BAT and supply those variables.

    In NT the SET command has a substring option. I can't remember it offhand, but if you check the help it will explain it so you could change the 05/01/2002 to 20020105 (metric date is best for sorting). After that it's just a case of ren %1 %CDATE%1


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Checked into it. This will work in a batch file on W2K (possibly NT as well). You need launch CMD.EXE with /V option though.
    :@echo off
    
    set TODAY=%DATE:~10,4%%DATE:~7,2%%DATE:~4,2%
    
    echo @echo off > \temp.bat
    for /R . %%x in (*.*) do echo ren %%x %TODAY%%%~nx >> \temp.bat
    call \temp.bat
    del \temp.bat
    

    You have to pipe the command to ren to a file because if you rename as you go the FOR command gets all confused.


Advertisement