开发者

using batch command file copy on daily basis

开发者 https://www.devze.com 2023-03-19 19:59 出处:网络
I need to copy files from one machine to my local disc using batch commands. My files contain the date in dd-mm-yyyyformat. But in case if i am using this:

I need to copy files from one machine to my local disc using batch commands.

My files contain the date in dd-mm-yyyy format. But in case if i am using this:

-%date:/=-%

it is interpreted as "day" and then date which is not really associated with my file name at the source end.

Once I click my bat file it will copy one folder say "xyz dd-mm-yyy" I want to copy only today's folder as on my source machine saved last 7 days folder.

EDIT: my folder name on source machine is Site_info 11-07-2011 and tomorrow one more folder will get added开发者_开发百科 to the same machine with name site_info 12-07-2011. I want to run the bat file machine where it will copy only today's folder.

EDIT2: Thanks for kind support still i am not able to achieve my target.If possible please provide the commands for following situation

My machine path :c:\Documents and Settings\user1\Desktop\SITE_INFO\Site_info 12-07-2011 where Site_info 12-07-2011 will change to site_info 13-07-2011

Source address :- \97.253.72.127\Cdma Site_info\Site_info 12-07-2011 Tomorrow one more folder will get add on this path with dated like \97.253.72.127\Cdma Site_info\Site_info 13-07-2011


If you mean that there's the 'day of week' part preceding the date and you want to get rid of that part, then you'll probably need an additional variable. First you'll cut off the day of week, then replace / with -, like you are already doing. It might be something like this:

…
SET "dateonly=%date:~4%"
SET "dateonly=%dateonly:/=-"
…
COPY \\computer\share\path\whatever-%dateonly%.ext drive:\path\%dateonly%\
…


You could try to puzzle the date the way you want it:

set mydate=%date:~-10,2%-%date:~-7,2%-%date:~-4%
xcopy /E /I "Site_info %mydate%" "Copy\Site_info %mydate%"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号