|
Answer» Hi. I have folder which are made dynamically and i wanted to copy the contents in them to another destination. The folder themselves only have one .txt file in them so that will be easy. However, to get into the right folder is what has me confused. The folders are named like....
2005-04-18 2005-04-19 2005-04-20
and the folder i want to open is the last one but the date on it is yesterday's. So i was thinking maybe to treat those as strings or something and sort them somehow. I have never programmed a batch file other than real simple ones so i have no clue how to do this.
the command i'm gonna issue in cmd is...
copy "c:\dated logs\%that last folder%\*.txt" "c:\Program Files\MySQL\MySQL Server 4.1\data\syslog"
Can someone please help me!I wrote this on the fly, but it may work:
for /F "tokens=1" %%i in ('dir /a:d /b /o:-d') do ( copy "c:\dated logs\%%i\*.txt" "c:\Program Files\MySQL\MySQL Server 4.1\data\syslog" goto endloop ) :endloop
The goto may fail because the tag is outside the loop. Give it a try and get BACK to us if you have any problems.
Hope this helps. %%i turns out to be "New" so it can't find the path cuz it doesn't existI tried this on my machine. I don't know where the 'new' came from. It appears the dir list did not come from the 'dated logs' directory. Also what OS are you using?
If you don't want to run from the 'dated logs' directory, use a path on the dir command.
Good luck. k, i changed a little bit of things, and it does copy but it does OPPOSITE of what i need it too.
this is what i ran...
c: cd "c:\Dated logs" for /f "tokens=1" %%i in ('dir /a:d /b /o:-d') do ( copy "c:\Dated logs\%%i\*.txt" "c:\Program Files\MySQL\MySQL Server 4.1\data\syslog" goto endloop ) :endloop
also, i get the same ouput from this batch file which someone else helped me with...
c: cd "c:\dated logs\" dir /b /ad /o-d>c:\tempdeep.dat set /ptempvar01=tempvar01copy "c:\dated logs\%tempvar01%\*.txt" "c:\Program Files\MySQL\MySQL Server 4.1\data\syslog" del c:\tempdeep.dat set tempvar01=
they both copy the first folder in the c:\dated logs folder, so that means its the oldest cuz its name is the oldest date
i need to get into the newest folder, the last folder in the c:\dated logs directoryOk, there's more than one WAY to skin a cat. the /o:-d switch causes the dir list to be reverse sorted on the date/time stamp of each directory. You can alway try /o:-n which will reverse sort on the directory name itself.
Hope this helps.
|