Page 1 of 1
copy extra files from source to target location
Posted: 14 Apr 2013 00:32
by javeedkaleem
Hi all
I am not aware of writing batch scripting and facing this issue very much in my day to day activity
I have a task to copy the files it may be *.jpeg or *.JPEG and *.jpg or *.JPG
and daily i have to manually copy the files which is not copied to target folder by cheking date & time.
Code: Select all
ex: source c:\source\
Name Type Date Modified
a00001 JPEG 4/13/2012 9:21AM
a00002 JPEG 4/14/2012 00:18AM
a00002 JPEG 4/14/2012 07:41AM
ex: Target c:\target\
Name Type Date Modified
a00001 JPEG 4/13/2012 9:21AM
as can see in target folder last file was copied on 13th apr 2013 @ 9:21AM
now need to copy files from source location after 13th apr 2013 @ 9:21 AM
any help will be appreciated.
also can any one give me a good link to learn batch scripting in basic and advanced level
are there any good books for learning batch scripting.
Regards
Kaleem.
Re: copy files from sourc to target location which is not co
Posted: 14 Apr 2013 00:58
by abc0502
So, you just want to copy all the files that isn't in the target folder, right ?
and what if a file with the same name but different time/date ? will you overwrite ?
And is there any other files in the source folder with the images ?
Re: copy files from sourc to target location which is not co
Posted: 14 Apr 2013 01:18
by javeedkaleem
Hi abc0502.
So, you just want to copy all the files that isn't in the target folder, right ?
and what if a file with the same name but different time/date ? will you overwrite ?
And is there any other files in the source folder with the images ?
I need to copy the files from source location to target location
yes i need to copy the files which is not present in target location
but present in Source location.
there will not be any same filename with different time/date.
and also target folder has different files like *.pdf *.docs also from this i need to copy only images to target location.
basically its a kind of incremental backup concept.
only changes in "source location" needs to be copied to "target location" with filter only image files.
Re: copy files from sourc to target location which is not co
Posted: 14 Apr 2013 01:27
by abc0502
This should do what you need,
Code: Select all
@Echo OFF
Color 0E
REM These Are the Location of your source and target folders
SET "Source=%userprofile%\desktop\New Folder\source"
SET "Target=%userprofile%\desktop\New Folder\target"
SET "Extensions=jpeg jpg"
REM Using Xcopy command to copy files incrementally based on last modification date/time
For %%A In (%Extensions%) Do (
XCopy "%Source%\*.%%A" "%Target%" /D /V /Q
)
Echo.
Echo Done!
pause >NUL
Change the locations of the source and target variables in lines 5 and 6 with your's
The Extensions is the file types, capital and small letters doesn't matter in batch, so
JPG is the same as
jpgIf you wanted to copy more file types just add it's extension to the extension variable, between each extension there must be a space as a separator.
Edited:Removed the >NUL from the For command, in case there was a file with the same name, you will be prompted for overwrite but you won't see it, and the script will appeared to be hanged.
Re: copy extra files from source to target location
Posted: 14 Apr 2013 02:21
by javeedkaleem
Hi abc0502
Excellent work. this script is working as i want but i am unable to understand this script.
its copying files with the extention and the files not present in target
guess the filters in xcopy /D /V /Q is doing the major part.
any ways very good appreciate your work.
can you give me some online documents to study batch scripting as an oracle dba i have good experience in working in Unix environment
but now we have databases and applications in windows also to automate the jobs i want to study more about batch scripting
i searched google but i did not find any book on windows batch scripting
can you give me some documents or links to study this subject.
Best Regards
Kaleem.
Re: copy extra files from source to target location
Posted: 14 Apr 2013 02:35
by abc0502
/D switch make the command copy only new files, with new modified date.
/Q is for quite mode, doesn't show output on screen
/V to verify copied files, to make sure they was copied alright.
The for command read the Extension variable and pass each extension to the xcopy command.
so any extention you add to that variable will be copied using the Xcopy command.
---
About the documentation, there is no online books i know about, but batch files is a basic commands of the CMD, all commands and it's documentation is in the "help", writing batch files it is the same as writing bash scripts.
And for any question, search here in dostips.com, i think every thing have been discussed, and if you don't find what you searching for, just post a new topic and every we will try to help.

Re: copy extra files from source to target location
Posted: 14 Apr 2013 07:09
by Squashman
javeedkaleem wrote:also can any one give me a good link to learn batch scripting in basic and advanced level
are there any good books for learning batch scripting.
Regards
Kaleem.
How did you miss the main site on your way into the forums.
http://www.dostips.com/