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

Batch programming problem

Options
  • 18-03-2005 12:38pm
    #1
    Registered Users Posts: 1,048 ✭✭✭


    Would anyone know how to pull a file from a directory using its date as a parameter?

    Basically I have a process running that pulls a file a couple times a day. There are approximately 100 files of the same type in the directory, so I cant copy by type. The file name changes every day so its name cannot be used as a parameter. Does anyone know of a way to perform this task, using the date last accessed/modified as the main parameter of the script,i.e.


    Copy the file with its date accessed/modified field closest to what the current system time is.

    Any suggestions are welcome... :)


Comments

  • Registered Users Posts: 7,276 ✭✭✭kenmc


    what sort of system are you using? win/*nix?
    i'll assume *nix. otherwise you're on your own

    do you just want the most recently modified one? or several of them...
    ls -t will give you them sorted cronologically, newest first. so you could grab this list, take the first element out of it and then copy that....


  • Closed Accounts Posts: 244 ✭✭osmethod


    Quote:"Basically I have a process running that pulls a file a couple times a day. There are approximately 100 files of the same type in the directory, so I cant copy by type. The file name changes every day so its name cannot be used as a parameter. Does anyone know of a way to perform this task, using the date last accessed/modified as the main parameter of the script"

    1. What system are you using...?
    2. Is this 1 file per day or are there multiple files per day?
    3. The 100 hundred files - are they cummulated in the same directory over time or all aon the same day?
    4. The file name changes every day - some examples of the sequence would help?

    osmethod


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


    I think you can do what you are suggest with XCOPY.

    Here is how I would do it using only batch scripts (.bat).
    :// Reads SCANDIR for files (not directories) and outputs only 
    :// those who match todays date to a file.
    dir %scandir% /a-d | find "%DATE%" > filelist.txt
    

    This will give you something like..
    18/03/2005  09:33                 0 0.log
    18/03/2005  09:33             2,048 bootstat.dat
    18/03/2005  12:14                 0 filelist.txt
    18/03/2005  10:31           387,897 WindowsUpdate.log
    

    In this instance column 36 is where the file name starts. So you just need to pull that out. The problem now is you need a program to parse that file.

    Personally I would go with ANT. It can do this sort of thing easy.


  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    Hobbes wrote:
    I think you can do what you are suggest with XCOPY.

    Here is how I would do it using only batch scripts (.bat).
    :// Reads SCANDIR for files (not directories) and outputs only 
    :// those who match todays date to a file.
    dir %scandir% /a-d | find "%DATE%" > filelist.txt
    

    Eek. Didn't know anyone did this sort of thing on Windows :)


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 91,687 Mod ✭✭✭✭Capt'n Midnight


    you might want to add /T and /AA (not backed up) to the dir command above
    and /m (don't copy again) to the xcopy one

    /T Controls which time field displayed or used for sorting timefield
    C Creation
    A Last Access
    W Last Written

    Another nasty hack that used to work on NT4 - produces recent.ext as a copy of the most recent file (you have to change the extension for obvious reasons)
    xcopy *.EXT Recent.TXE /m


  • Advertisement
  • Registered Users Posts: 1,048 ✭✭✭BobTheBeat


    Thanks guys for your feedback. Its windows machine Im gonna be runnin this on, eek is right! :eek:

    Will try the XCOPY routine and see how I get on... Thanks mate


Advertisement