Xcopy

I am trying to create a script to copy files from one folder to another as a scheduled task throughout the day.  I only want to copy docs, excel files, and pdf's.  I know how to use xcopy, but I've never excluded files.  Can anyone help with this?
zmccrawAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MikeIT ManagerCommented:
I don't believe you can exclude files using xcopy.
0
Steven HarrisPresidentCommented:
Try using ROBOCOPY:

ROBOCOPY <Source> <Destination> *.pdf *.xls *.doc [options]

Open in new window


Use /L for testing... then add in what you need form the list below:

/S : Copy Subfolders.
/E : Copy Subfolders, including Empty Subfolders.
/L : List only - don’t copy, timestamp or delete any files.
/Z : Copy files in restartable mode (survive network glitch).
/B : Copy files in Backup mode.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Steven HarrisPresidentCommented:
I don't believe you can exclude files using xcopy.

Sure you can Shadowless127, it is just easier to use ROBOCOPY in my opinion.

To exclude certain files with xcopy, use:

/EXCLUDE:file1[+file2][+file3]...

Open in new window


For example, specifying a string like \obj\ or .obj will exclude
-all files underneath the directory obj or
-all files with the .obj extension, respectively.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Bill PrewCommented:
You could of course do multiple XCOPY commands in a BAT file. This might be a little slower than robocopy, but if the folder structure isn't too huge and you aren't running it too often could work.

@echo off
xcopy /s c:\temp\*.pdf d:\dest
xcopy /s c:\temp\*.doc* d:\dest
xcopy /s c:\temp\*.xl*pdf d:\dest

Open in new window

~bp
0
Steven HarrisPresidentCommented:
billprew, good catch on the *.doc* and *.xls* but it looks like you through in an extra 'psd' in there after the excel files.

That will definitely be helpful for all file versions and formats!
0
zmccrawAuthor Commented:
Is there a way to copy only new or modified files, or will it continuously copy everything?  We are using this to copy files a user creates to a specified folder which is then synced with the server.  I've never used Robocopy.
0
MartinCookJrCommented:
zmccraw,

XCOPY can be used to exclude files with specific extensions , (.txt .exe .doc) or file names, but it cannot be used to only allow certain extensions. Basically you can specify what you dont want but not what you want. In the directory that your moving docs from is this a shared folder were there is a whole bunch of different types of documents or is it pretty standard to as far as the types of documents that are in the folder? If you know for sure that the only other files you have are for example .gif then you can use this command to make sure that no .gif files will be moved over.

C:\>xcopy "C:\" /exclude:ex.txt " D:\"

Now the /exclude must point to a text file that includes the extensions or filenames that you do not wish to copy. So create a text document under the directory from which you will be running the command (in this example its just C:) name it whatever you want and for this example when you open the text document just type .gif and save it, make sure the file name is correct after the /exclude: portion of the command and that should do it.

This will copy over all files that do not have the .gif extension in there name. If you can use this command to accomplish what you need done you can just save it as a batch file and point the task scheduler to it.

MCook
0
MartinCookJrCommented:
Looking at my previous post you can use the /M option which will only copy over files with the archive attribute set, meaning changes that were made to it or that they are new files the new command would look like this C:\>xcopy /M "C:\" /exclude:ex.txt " D:\"

That goes for robocopy also you will use the /M file selection option and it will do the same thing that xcopy does for it.
0
Steven HarrisPresidentCommented:
Is there a way to copy only new or modified files, or will it continuously copy everything?

With robocopy use /xo

You can also throw in a /MOT:30 that will monitor your folder every 30 minutes and copy over the new/changed files with that /xo switch.
0
Bill PrewCommented:
Sorry, typo imn earlier post.  And you might want the /D option to only copy updated and new files.

@echo off
xcopy /s /d c:\temp\*.pdf d:\dest
xcopy /s /d c:\temp\*.doc* d:\dest
xcopy /s /d c:\temp\*.xl* d:\dest

Open in new window

~bp
0
zmccrawAuthor Commented:
Thank you for your help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.