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

Simple DOS help needed

Options
  • 08-06-2008 12:55pm
    #1
    Moderators, Politics Moderators Posts: 39,827 Mod ✭✭✭✭


    I have developed a small batch program that writes FTP instructions to a file, and then runs the file allowing me to download a file from the ftp location.
    However, the files are downloaded from a folder with the file creation date as the foldername (YYYYMMDD) and I need to grab yesterdays file from the server.
    How can I get yesterdays date and format it in the manner above?
    TIA


Comments

  • Closed Accounts Posts: 8 allexxei


    http://www.computerhope.com/batch.htm#5

    Here is a sample of how to work with date and time on DOS, You can find other samples on that website

    It will be better for you to work with more powerfull scripting languages, because this one is very limited


  • Registered Users Posts: 5,141 ✭✭✭Yakuza


    If you're on a Windows platform, check out Windows Scripting Host, it's far more powerful than the oldschool DOS commands:

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


  • Moderators, Politics Moderators Posts: 39,827 Mod ✭✭✭✭Seth Brundle


    Cheers.
    From what I have been told, they have been blocked by the firewall and I was specifically asked to do it this way. I already had the code running using VBA from MSAccess but it won't work within the client's network.
    I will see if I can adjust it and just use a VBS file.


  • Registered Users Posts: 6,465 ✭✭✭MOH


    From this recent thread, you could get the current date (yyyymmdd) using:
    for /F "tokens=1-3 delims=/ " %%I in ('date /t') do set datetag=%%K%%J%%I
    
    and maybe get the previous date with some messing around.


    Or, if you have access to run commands against your download location, I think this might do it:
    for /F %%I in ('dir <downloadfolder> /AD /ON /B') do set mydir=%%I
    

    That will basically:
    - Do a dir of all directories (the /AD switch) that folder in name order (/ON) and just give you back the folder names with no other info (/B)
    - parse the output of each line of the results, setting %%I to each line in turn and setting variable mydir to %%I
    - so at the end, mydir contains the last directory listed, which if they're all in the format yyyymmdd should be the most recent. You could also use /OD instead of /ON to return the files in date order. And there's a /T flag which lets use specify which date to use - creation, last write or last access. If you do dir/? on a command line it'll list the options.

    Of course, if there's other folders than your yyyymmdd ones in that folder, you'll have a problem, but changing it to
    ('dir <downloadfolder>[b]/20*[/b] /AD /ON /B')
    
    should get around that, giving you all folders starting with 20 which should work (for the next 92 years).

    Finally, to reference the mydir variable later in your script, use %mydir%


  • Moderators, Politics Moderators Posts: 39,827 Mod ✭✭✭✭Seth Brundle


    thanks folks


  • Advertisement
Advertisement