[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

bat file to copy files

Posted on 2010-04-05
11
Medium Priority
?
746 Views
Last Modified: 2012-05-09
Hi,

I am using peersync software to syncrhonize my oracle data to remote location. Now I want to copy the synchronized data to 7 weekdays folders. I want to run a single bat file to do this.

i have 7 folders mon, tue...sun. The syncrhonized folder name is daily. Once the synchronize happed i want to run a script/bat file so that it should copy the files inside daily folder to mon,tue... depending on todays week day.

how Ican do this
teks
0
Comment
Question by:teksalah
  • 3
  • 3
  • 2
  • +3
11 Comments
 
LVL 13

Expert Comment

by:luc_roy
ID: 29780698
xcopy.exe

Just xcopy /s c:\source d:\target

Here are all the commands

•/s/e - recursive copy, including copying empty directories.
•/v - add this to verify the copy against the original. slower, but for the paranoid.
•/h - copy system and hidden files.
•/k - copy read-only attributes along with files. otherwise, all files become read-write.
•/x - if you care about permissions, you might want /o or /x.
•/z - if you think the copy might fail and you want to restart it, use this. It places a marker on each file as it copies, so you can rerun the xcopy command to pick up from where it left off.

here is a link to someone who did a similar project

http://answers.google.com/answers/threadview/id/254582.html
0
 

Author Comment

by:teksalah
ID: 29782613
this will copy only to one target.. But I have 7 targets D:\monday; D:\tuesday... D:\sunday.  So on daily basis I want to copy to specific folders. On monday I want to copy to D:\monday and so on using one bat file

teks
0
 
LVL 72

Expert Comment

by:Qlemo
ID: 29782991
Could you please provide the output of this commands:

echo %date%
date /t

Depending on that, it might be necessary to use VBScript instead of a batch file.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 26

Expert Comment

by:Farhan Kazi
ID: 29784152
Check following batch script, if this works for you!

@ECHO OFF

SET DAY=%DATE:~0,3%
SET MM=%DATE:~4,2%
SET DD=%DATE:~7,2%
SET YYYY=%DATE:~10,4%

SET SPath=C:\Daily
SET TPath=D:\WeekDays\%DAY%

IF NOT EXIST "%SPath%" ECHO Invalid source. &Goto :End
IF NOT EXIST "%TPath%" ECHO Invalid target. &Goto :End

XCOPY "%SPath%" "%TPath%" /E /C /H /R /Y

:End
EXIT /B 0

Open in new window

0
 
LVL 72

Expert Comment

by:Qlemo
ID: 29784299
The locale settings may provide the weekday in %date% or not, that is why I asked for the output of the commands. The code above will not work on my system - no weekday here!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 29794322
You have it handled there between Qlemo andfarhankazi if your date format is OK but there is some more info. on getting date entries such as weekday here in my article:

http://www.experts-exchange.com/articles/OS/Microsoft_Operating_Systems/MS_DOS/Using-dates-in-batch-files-scripts.html
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 29794438
Once you have %weekday% etc. in a variable of course it is easy to do an xcopy c:\oldpath c:\%weekday% /s /d /y etc.
0
 
LVL 72

Expert Comment

by:Qlemo
ID: 29798238
Yes, Steve, sorry I didn't think of including a link to this great article. Will you forgive me?
0
 
LVL 60

Expert Comment

by:Bill Prew
ID: 29803620
A couple of thoughts:

First, is there no way in peersync to do this, it seems like a fairly robust tool, does it no allow intellignetly selecting a destination directory?  Or if you are running it in a batch file on the server, perhaps you should add logic to that existing batch file to pass in the destination folder on the command line, rather than having a new batch file?

Also, if you do need to proceed with the approach in this question, with a seperate batch file to run after the fact, I'd recommend going off of the date stamp of the actual file, rather than the current data.  This way if you have more than one days files in the collector folder, or for some reason the breakout script doesn't run on the same day as the peersync job, it still sends the files to the correct day of the week subfolder.  This approach feels more failsafe to me, and more robust, with not a lot more work.

~bp
0
 

Author Comment

by:teksalah
ID: 29877407
HI,  The below batch file will run after the peer-sync completes the synchronization and copies the synchronized files depending upon the weekdays. Only one issue is , it should run before 23.59Hrs, Otherwise it will copy to the next day.


@ECHO OFF

for /f %%a in ('date /t') do set DAY=%%a
if %DAY%==Mon goto:mon
if %DAY%==Tue goto:tue
if %DAY%==Wed goto:wed
if %DAY%==Thu goto:thu
if %DAY%==Fri goto:fri
if %DAY%==Sat goto:sat
if %DAY%==Sun goto:sun

:mon

copy d:\daily\*.* d:\weekly\monday\

goto:end

:tue

copy d:\daily\*.* d:\weekly\tuesday\

goto:end

:wed

copy d:\daily\*.* d:\weekly\wednesday\

goto:end

:thu

copy d:\daily\*.* d:\weekly\thursday\

goto:end

:fri

copy d:\daily\*.* d:\weekly\friday\

goto:end

:sat

copy d:\daily\*.* d:\weekly\saturday\

goto:end

:sun

copy d:\daily\*.* d:\weekly\sunday\

goto:end

:end
=================================

any comments appreciated
teks
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 total points
ID: 29883505
Comments:

1. This depends upon the date format used by the user scheduling the script.  Be careful (which is why I suggested VBScript approach to grab the date).

2. Why not just use directories called Mon, Tue, Wed etc. or if you want to use the method you have but save some code then you could shorten it to:

@ECHO OFF

for /f %%a in ('date /t') do set DAY=%%a
if %DAY%==Mon call :backup Monday
if %DAY%==Tue call :backup Tuesday
if %DAY%==Wed call :backup Wednesday
if %DAY%==Thu call :backup Thursday
if %DAY%==Fri call :backup Friday
if %DAY%==Sat call :backup Saturday
if %DAY%==Sun call :backup Sunday
exit /b

:backup
  copy d:\daily\*.* d:\weekly\%1\
exit /b

or

for /f %%a in ('date /t') do set DAY=%%a
if %DAY%==Mon copy d:\daily\*.* d:\weekly\Monday\
if %DAY%==Tue copy d:\daily\*.* d:\weekly\Tuesday\
if %DAY%==Wed copy d:\daily\*.* d:\weekly\Wednesday
if %DAY%==Thu copy d:\daily\*.* d:\weekly\Thursday
if %DAY%==Fri copy d:\daily\*.* d:\weekly\Friday
if %DAY%==Sat copy d:\daily\*.* d:\weekly\Saturday
if %DAY%==Sun copy d:\daily\*.* d:\weekly\Sunday
exit /b

or

for /f %%a in ('date /t') do set DAY=%%a
copy d:\daily\*.* d:\weekly\%day%
exit /b

Personally I'd put some error checking in there, probably look to see if the dir existed first, maybe email notifications.  Need to deal with what files may or not be there in the Monday directory say on the second Monday it runs etc.

Steve
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Suggested Courses

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question