banner



How To Create Batch File To Copy Files From Folder

  1. Home
  2. Programming
  3. IT Programming

I've been at this for over an hour and I just can't get it right.  I've been playing with xcopy.

This is all I need to do.
Copy C:\Test to D:\Test and all it's files and sub folders.

I'm looking to have the folder "Test" on D:\ be created if it doesn't exist.
Each time the batch file launches, it should overwrite D:\Test if it exists.

Can someone help me out?

My head hurts.


Captain Frostbyte
Captain Frostbyte This person is a Verified Professional
This person is a verified professional.
Verify your account to enable IT peers to see that you are a professional.
Feb 8, 2016 at 19:46 UTC

if not exist D:\test  mkdir d:\test

xcopy /e c:\test d:\test

Should do what you need

Popular Topics in IT Programming

The help desk software for IT. Free.

Track users' IT needs, easily, and with only the features you need.

8 Replies

Gorfmaster1
Gorfmaster1 This person is a Verified Professional
This person is a verified professional.
Verify your account to enable IT peers to see that you are a professional.
Feb 8, 2016 at 19:38 UTC

Try using powershell to do it using this command

                                                            Copy-Item                              -Path                              "C:\Test"                              -Destination                              "d:\Test"                              -Recurse                            
T'zonarin
T'zonarin This person is a Verified Professional
This person is a verified professional.
Verify your account to enable IT peers to see that you are a professional.
Feb 8, 2016 at 19:39 UTC

Assuming this is a Windows machine and that you have proper rights for source and destination, here's what I would try (or variant thereof):

                              xcopy c:\test d:\test /e /h /y                            

/e will copy folders, even if they are empty.
/h will copy hidden and system files
/y will suppress the prompt to overwrite (necessary when batch copying)

Look at the switch list by typing xcopy /?

Tzo

Capef3ar
Capef3ar This person is a Verified Professional
This person is a verified professional.
Verify your account to enable IT peers to see that you are a professional.
Feb 8, 2016 at 19:41 UTC

Try this (if you're wanting to use a batch file):

move C:\Test D:\Test /Y

AdmiralKirk
AdmiralKirk This person is a Verified Professional
This person is a verified professional.
Verify your account to enable IT peers to see that you are a professional.
Feb 8, 2016 at 19:42 UTC

If you intend to flush the contents of d:\test every time then implement that task as its own line, then run your xcopy as a second line.  Don't try to make xcopy do both items, you don't have to

del d:\test\*.* /f /s /q

xcopy c:\test d:\test /s

This will delete all the contents and subfolders on d:\test, then copy all the content and (non-empty) subfolders from c:\test to d:\test
Support Guy

is there a way to bypass this message?  Seems to work file if I press D.

Does C:\Test specify a file name or directory name on the target

(F = file, D = directory)?

Captain Frostbyte
Captain Frostbyte This person is a Verified Professional
This person is a verified professional.
Verify your account to enable IT peers to see that you are a professional.
Feb 8, 2016 at 19:46 UTC

if not exist D:\test  mkdir d:\test

xcopy /e c:\test d:\test

Should do what you need

Captain Frostbyte
Captain Frostbyte This person is a Verified Professional
This person is a verified professional.
Verify your account to enable IT peers to see that you are a professional.
Feb 8, 2016 at 19:47 UTC

you could always just use robocopy to keep them in sync.  works well

Support Guy
Final Product that worked for what I need to do.  It's a long story, but thanks guys.

del %userprofile%\Test\*.* /f /s /q

if not exist %userprofile%\Test  mkdir %userprofile%\Test

xcopy C:\Test %userprofile%\Test /e /h /y

This topic has been locked by an administrator and is no longer open for commenting.

To continue this discussion, please ask a new question.

How To Create Batch File To Copy Files From Folder

Source: https://community.spiceworks.com/topic/1433800-need-help-with-a-batch-file-to-copy-one-folder-to-a-new-location

Posted by: mcdonnellturper.blogspot.com

0 Response to "How To Create Batch File To Copy Files From Folder"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel