Jaffer Wilson
Jaffer Wilson

Reputation: 7273

Copying of file using .bat

I have written the following code and am trying to copy all the files to the location. The following line works when I paste it on cmd but it doesn't work in the batch file:

for %I in (*.m) do (copy /Y %I "%appdata%\Math\include")
pause

Kindly, let me know what I am missing?

I have tried to follow the answers from here: Can I copy multiple named files on the Windows command line using a single "copy" command?
But no use to me. Please share your suggestions.

Upvotes: 0

Views: 422

Answers (1)

Danny_ds
Danny_ds

Reputation: 11406

You could just use copy or xcopy:

copy /y *.m newDir

However, if newDir does not exist copy will create a file named newDir

To avoid that xcopy /i can be used instead:

xcopy /y /i *.m newDir

To include subdirectories use xcopy /s:

xcopy /y /i /s *.m newDir

or shorter:

xcopy /yis *.m newDir

There is also the newer Robocopy.

Upvotes: 1

Related Questions