| 1. |
Solve : bat file to copy files from folder with changing name YYYYMMDD? |
|
Answer» I am needing to write a bat file that copies files from a folder whose name changes daily and I need to copy those from YESTERDAYS folder. I.e. if TODAY is feb 12, 2010 i need to copy files from folder 20100211 and tomorrow I will need to copy from folder 20100212. Can anyone help me? THANKS in advanceOpen up the command prompt and type in Code: [Select]echo %date% then post what is displayed on the screen. We need to know this so we can make a code that works for your date format.it's : Sat 02/13/2010Watch out for the end-of-the-month...i could also approach this by copying contents of the most recent folder where folder name is like YYYYMMDD to a folder named current. Would this make it any more doable?pls answer helpmeh's question. pls answer helpmeh's question.Quote from: jonfrye on February 13, 2010, 10:16:53 AM it's : Sat 02/13/2010Quote from: Helpmeh on February 14, 2010, 03:19:35 PM Sorry I must be going blind. Anyhow, we don't really need the date format if we can use VBS. Code: [Select]@echo off Echo Wscript.echo eval(WScript.Arguments(0))>evaluate.vbs For /f "delims=" %%A in ('cscript //nologo evaluate.vbs "year(date-1)"') do set YYYY=%%A For /f "delims=" %%B in ('cscript //nologo evaluate.vbs "month(date-1)"') do set MM=%%B For /f "delims=" %%C in ('cscript //nologo evaluate.vbs "day(date-1)"') do set DD=%%C del evaluate.vbs if %MM% LSS 10 set MM=0%MM% if %DD% LSS 10 set DD=0%DD% set sourcefolder=%YYYY%%MM%%DD% set filespec=*.* set destinfolder=c:\whatever\whatever copy "%sourcefolder%\%filespec%" "%destinfolder%" Outstanding, thanks very much--I APPRECIATE it immensely.Quote from: Salmon Trout on February 14, 2010, 03:39:26 PM
this can be shortened (by combining the evals) so that you don't have to call cscript.exe engine 3 times. Quote from: ghostdog74 on February 14, 2010, 08:30:17 PM this can be shortened (by combining the evals) so that you don't have to call cscript.exe engine 3 times. Indeed. And you can eliminate the parameter passing altogether. Code: [Select]@echo off REM must use sign - or + set diff= -1 Echo Wscript.echo year(date%diff%) ^& "," ^& month(date%diff%) ^& "," ^& day(date%diff%)>datecalc.vbs For /f "tokens=1-3 delims=," %%A in ('cscript //nologo datecalc.vbs') do ( set YYYY=%%A set MM=%%B set DD=%%C ) del datecalc.vbs if %MM% LSS 10 set MM=0%MM% if %DD% LSS 10 set DD=0%DD% set foldername=%YYYY%%MM%%DD% |
|