Google Answers Logo
View Question
 
Q: Create a batch file to copy and paste specific files. ( Answered,   0 Comments )
Question  
Subject: Create a batch file to copy and paste specific files.
Category: Computers > Programming
Asked by: 16582jade-ga
List Price: $20.00
Posted: 11 Sep 2003 08:30 PDT
Expires: 11 Oct 2003 08:30 PDT
Question ID: 254582
How do I create a batch file to select specific files to be copied and
pasted to a CD-RW upon execution of the batch file?  The files reside
on a server (F: drive) in a specific folder and I work with several
individual offices that are required to copy the files to a CD-RW on a
daily basis.  To ensure they are selecting the correct files, can a
Batch file work for this rather than the person selecting the files
and copy?  We work in Windows XP Professional and purchasing special
software is not an option.
Answer  
Subject: Re: Create a batch file to copy and paste specific files.
Answered By: slawek-ga on 11 Sep 2003 16:33 PDT
 
Good Day 16582jade,


A batch file will do the job just fine. Please, before you try any of
the following, backup all your data onto a CD and put it aside... just
in case something goes wrong.

For this example I am going to assume that your CD-RW is in drive G:
and that all your files are on Drive F: in the root directory.

Sample code:

XCOPY F:\*.* G:\ /C /S /D /Y /I

Let's break things down:
XCOPY allows for copying of files, directories, and sub directories.
F:\*.* is our source location
G:\ is our destination location
/C tells XCOPY to ignore errors, and finish what can be done
/S tells XCOPY to copy everything including directories and
subdirectories
/D tells XCOPY to only copy source files that are newer than the
destination files (big time saver on the process)
/Y tells XCOPY to overwrite files without asking for confirmation
/I tells XCOPY to automatically create new directories on the
destination, if new directories were created in source.

Now, let us say that the files you want copied are on drive F, in the
directory/folder called "GOOGLE", and your CD writer is still G:

XCOPY F:\GOOGLE\*.* G:\GOOGLE\ /C /S /D /Y /I

In this example, you would have to manually create the GOOGLE
directory on drive G: .  Of course, you only would need to do this
once. All subdirectories in GOOGLE would get transferred
automatically. Why does GOOGLE have to be created on the CD? Well, our
source specification already entered the directory GOOGLE (XCOPY
F:\GOOGLE\...) The /I switch only works on directories after the
current path. The current path has to exist, and the /I switch will
create the subdirectories that follow.

With the code copied, paste it into notepad, and update the locations
to reflect your actual drives and folders. Save the file as
filename.bat and for ease of use create a shortcut to the file from
the desktop.

You can further customize these batch files to include specific files,
but things will get messy. I would recommend having the files you need
backed up all in one directory, and just copying over the whole
directory each time. This will ensure that any new files created get
copied automatically, without the need to ever change the batch file.
As long as any new files are put into the directory specified in the
batch file (or a subdirectory of it), they will get copied.

There is no limit on how many lines you can have in a batch file, so
you can repeat this code as often as you wish with different sources
and destinations. However, if everything is in subdirectories of the
source destination, all you need is the one line. Multiple lines are
required for directories not on the same branch, or if you only wish
to copy select subdirectories of the source.

I hope this helps more then confuses. I have also found an article
that goes through very similar steps:

WEBSITE: Backup Important Files With This Simple Batch File.
URL: http://techrepublic.com.com/5100-6270-1051305.html

A suggestion made in the article is to have the batch file executed
via the Task Scheduler. An option you might find useful if anyone
tends to forget to go through the backup process.

Please do not hesitate to ask for a clarification if you require
further assistance. I will be happy to help you in any way I can. If
you are not sure how to modify the code, please send me a full list of
files/locations you need backed up, and I will write the code for you.

Thank you for choosing Google Answers.

SEARCH STRATEGY: 
Google Search for "batch file"+"learn"+"simple"


Regards,
slawek-ga
Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy