Jump to content

How 2 write a batch file that copies files but NOT


ceez

Recommended Posts

Zup peeps!?

I want to create a batch file that copies files from a directory but does not copy folders from that directory. I checked the xcopy & copy command options with the /? switch but they dont say anything about not copying dirs.

Is it possible?

Thkz

ceez

:thumbup

Link to comment
Share on other sites


@soulin, thkz for the info, found robocopy and it has an exclude option which i could use for the foldes, but if new folders are created then I would have to tweak the batch file every time. I will give it a try anyways,

Any other ideas?

Thkz again,

ceez

:thumbup

PS- i cant even get it to work, the command just scrolls down the cmd prompt non-stop.

this is what I am testing.

C:\A <- folder has source files and folders

C:\B <- destination folder for everything in A (including the folders for now)

Using the followin in my batch:

robocopy c:\a\*.* c:\b\

pause

exit

When I run it all I get is the command scrolling down and nothing gets copied, it's not a lot of files either. :( help.

PS 2 - I just found out that the copy command apprently DOES NOT copy directories. I just tried the above commands but used "copy" and when I checked the B folder it had all the files an no dirs...cool....

well that seems to be the end of my mission.

thkz

Link to comment
Share on other sites

COPY C:\OLDdir\*.* C:\NEWdir

If you try to copy multiple files to a subdirectory that does not exist, using copy, the subdirectory will not be created, you would need to first 'make' the 'directory', (MD), therefore

IF NOT EXIST C:\NEWdir MD C:\NEWdir
COPY C:\OLDdir\*.* C:\NEWdir

Now if C:\OLDdir cannot be found, you will get an error and will have created a directory for no reason, therefore

IF EXIST C:\OLDdir (
 IF NOT EXIST C:\NEWdir MD C:\NEWdir
 COPY C:\OLDdir\*.* C:\NEWdir
)

I hope this helps to show you how you 'build' a batch script using a series of small steps!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...