|
Answer» Hi
Can anyone help. First time using this forum
I want to copy a folder to another location. Thats OK using xcopy.
I want the .bat to search the folders for the folder named with todays date and then copy it.
The folder is named with todays date 04122008 and located in C:\Documents and Settings\jbloggs\Desktop\2008\December
I want the batch file always copy specifically todays folder to new location. the path of the source folder will always be yyyy/month/ (ie...2008/December)
ECHO OFF set nl=C:\Docume~1\jbloggs\desktop\2008\december set td=%date:~7,2%%date:~4,2%%date:~10,4% if not exist %nl%\%date:~4,2%\%date:~10,4% mkdir %nl%\%date:~4,2%\%date:~10,4% for /f "tokens=1*" %%a in ('dir /a:d ..\%td% /b /s') do copy "%%a %%b\*" "%nl%\%date:~4,2%\%date:~10,4%\* ::set nl=YOURfolder ::set td=the date DAYMONTHYEAR FORMAT ::if not exist YOURfolder\MONTH\YEAR create it ::for all folders with todays date in DAYMONTH YEAR FORMAT , COPY all Contents to YOURfolder\MONTH\YEAR CLSWelcome to the CH forums.
Try this. You didn't supply the destination path/filename details so they are OMITTED. The code will extract date info regardless of the date format in your pc and will change to a new year/month depending on your date.
With acknowledgement to Dias de verano.
Code: [Select]echo off cls
:: Create/run vbs file (extracts date components) & set variables.. :: set vb=%temp%\newdate.vbs echo Newdate = (Date() ) > %vb% echo Yyyy = DatePart("YYYY", Newdate) >> %vb% echo Mm = DatePart("M" , Newdate) >> %vb% echo Dd = DatePart("D" , Newdate) >> %vb% echo Wd = DatePart("WW" , Newdate) >> %vb% echo Wn = DatePart("Y" , Newdate) >> %vb% echo Ww = datepart("W" , Newdate) >> %vb%
echo Wscript.Echo Yyyy^&" "^&Mm^&" "^&Dd^&" "^&Wd^&" "^&Ww^&" "^&Wn >> %vb%
FOR /F "tokens=1-6 delims= " %%A in ('cscript //nologo %vb%') do ( set Year=%%A set Month=%%B set Day=%%C set Week#=%%D set Weekday#=%%E set Day#=%%F ) del %vb%
If %Month% lss 10 set Month=0%Month% if %Day% lss 10 set Day=0%Day%
set Today=%Day%%Month%%Year% for /f "Tokens=%Month%" %%A in ( "January February March April May June July August September October November December") do ( set Alfamonth=%%A )
set Filename="c:\documents and settings\jbloggs\desktop\%Year%\%Alfamonth%\%Today%" echo Source path\ echo filename = %Filename% echo. echo Today = %Today% echo Year = %Year% echo Alpha month = %Alfamonth%
:: NOT TESTED FROM THIS LINE.....
:: DESTINATION PATH/FILENAME UNKNOWN.....
if exist %Filename% xcopy %Filename% (Destination path/filename here)
Good luck. Wow .... Thanks for the response both.
The code seems to work up to the point of copying to new destination. C:\Documents and Settings\jbloggs\Desktop\copy
I can't get it to copy, but it is LOCATING the source
I have added the path name to the code
if exist %Filename% xcopy %Filename% C:\Documents and Settings\jbloggs\Desktop\copy
I would appreciate more ASSISTANCE..
This stuff is great....but I'm a noviceHi
I got it to work. The original path name has spaces, once I removed spaces with new source location and destination it worked. I also added /e to xcopy %Filename%
xcopy /e %Filename% /E Copies directories and subdirectoriesOk on that, your original destination path has spaces so must be enclosed in " "
See this line in the code for an example:
Code: [Select]set Filename="c:\documents and settings\jbloggs\desktop\%Year%\%Alfamonth%\%Today%" Hi Thank you
I have added \e and \v to but now is asking me to specifiy a file name ((F = file, D = Directory)
The reason I have added \v was to run this automatcally through out the day, but avoid manual input. Now I have specify a filename?
How can I overcome this?I have added /I
"/I If destination does not exist and copying more than one file, assumes that destination must be a directory. "
However I am trying to copy to destination path which also has spaces. I works fine if path has no spaces. Can I get around this?
For Example: C:\DOCUMENT and Settings\Copy Of Files
would it also work C:\Document and Settings\Copy Of Files\%Year%\%Alfamonth%\%Today%
Quote from: petreli However I am trying to copy to destination path which also has spaces. I works fine if path has no spaces. Can I get around this?
For Example: C:\Document and Settings\Copy Of Files
would it also work C:\Document and Settings\Copy Of Files\%Year%\%Alfamonth%\%Today%
As i already posted
Quote from: Dusty - reply #5Ok on that, your original destination path has spaces so must be enclosed in " "
so enclose your destination path/filename in double quotes which I show in red below for emphasis. And yes, using the environment variables will work:
"C:\Document and Settings\Copy Of Files\%Year%\%Alfamonth%\%Today%"
Quote from: petreliI have added \e and \v to but now is asking me to specifiy a file name ((F = file, D = Directory)
I've never had reason to use Xcopy so am not well versed in its use but adding a backslash at the end of your destination path might get round the problem. e.g.
"C:\Document and Settings\Copy Of Files\%Year%\%Alfamonth%\%Today%\"
Thank you ...this work perfectWell done - great performance. Thank you for COMING back to report your success.
D.
|