Saved Bookmarks
| 1. |
Solve : get file based on most current date? |
|
Answer» I’m working on something using an FTP command. I’m trying to FTP a file from /SYSRES/SHOPPERS to a network directory….but, I only want the current file. The file has a date/time stamp, but I only care about the date. The most current file is named SHOP010907112030. How can I add to check for the date to my batch script? Tomorrow's file would be SHOP011007HHMMSS. Let me know if you can help….thanks much. I’m working on something using an FTP command. I’m trying to FTP a file from /SYSRES/SHOPPERS to a network directory….but, I only want the current file. The file has a date/time stamp, but I only care about the date. The most current file is named SHOP010907112030. How can I add to check for the date to my batch script? Tomorrow's file would be SHOP011007HHMMSS. Let me know if you can help….thanks much. I have an idea as to how you could get tomorrow's date into an environment variable. Would that help? ... could you work with it then? The time of day part - don't know how to HANDLE that. Sorry. . I don't want to set an environment variable because both of these files are on DIFFERENT servers. I just want to disregard the time part and I want this to be variable so when it runs, it will always get todays file. thanks much.Quote I don't want to set an environment variable because both of these files are on different servers. Can you explain that a bit? Why is the files being on different servers important? Quote I just want to disregard the time part and I want this to be variable so when it runs, it will always get todays file. thanks much. Set today's date in an environment variable then - if you can use it that way. It's always HELPFUL if you mention what version of DOS or Windows you're running as batch language changes often. One way would be to sort the files descending by date and skim off the top one. See Previous Post The other would be to localize the environment variable to the batch file: Code: [Select]setlocal set today=%date:~4,2%%date:~7,2%%date:~12,2% echo %today% endlocal The above snippet is just an example but you can incorporate the setlocal/endlocal in your own batch file. Good luck. 8-) Disclaimer: This will only work on some machines, maybe even yours!Ok...I'm new to this, so bare with me! I'm running windows XP. I still don't understand why/how to set the environment variable to help me. In the example pasted above for sorting and skimming 1 off the top, I tried that and it didn't work...perhaps I missed something? Could you repeat that slowly for the newbie Thanks!Quote In the example pasted above for sorting and skimming 1 off the top, I tried that and it didn't work Not knowing how or what you ran, it's hard to tell what went wrong. The example below will sort all the files beginning with SHOP descending by date. The most recent file will sort first where you can use it in the context of your FTP COMMANDS. (the %%i variable contains the file name) Code: [Select]@echo off for /f %%i in ('dir SHOP*.* /tc /o:d /a-d /b') do ( ftp commands go here goto tag ) :tag The next example is much the same, but uses a local variable containing today's date: (the filename is still in %%i) Code: [Select]@echo off setlocal set today=%date:~4,2%%date:~7,2%%date:~12,2% for /f %%i in ('dir SHOP%today%*.* /tc /o:d /a-d /b') do ( ftp commands go here goto tag ) :tag endlocal You still have to put the appropriate FTP commands where INDICATED. You may also have to include path information based on your environment. 8-) |
|