Computing.Net > Forums > Programming > Batchfile to copy folders

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batchfile to copy folders

Reply to Message Icon

Name: Remo
Date: September 24, 2009 at 04:27:20 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

Hi.. I would like to know if it is possible to move/copy folders from one location to another location. All my folders are named as X_A_Y_htmls, X_B_Y_htmls, X_C_htmls. I tried using X_*_Y in the move command, but it treats it as a duplicate. Do i need to use looping for this? If yes, please illustrate. Thanks in advance



Sponsored Link
Ads by Google

Response Number 1
Name: Judago
Date: September 24, 2009 at 04:49:36 Pacific
Reply:

Something like this perhaps?

for /d %%a in (X_?_Y_htmls) do move "%%~fa" "folder"

for /d %%a in (X_?_Y_htmls) do xcopy /e /i /-y "%%~fa" "folder\%%~nxa"

[edit]
They are two separate commands, one moves the other copies.
They shouldn't be used togther.
[/edit]


1

Response Number 2
Name: Remo
Date: September 24, 2009 at 05:23:46 Pacific
Reply:

Thanks.. Its working for the case ?_1594 or ?_1987 to put A_1594,B_1594,C_1594 or A_1987,B_1987,C_1987 into two folders 1594 and1987. The case its not working is ?xyz to put Axyz or Bxyz in xyz folder. There are around 10 files ie Axyz,Bxyz,Cxyz... which should go into xyz folder.


0

Response Number 3
Name: Judago
Date: September 24, 2009 at 05:39:40 Pacific
Reply:

"There are around 10 files ie Axyz,Bxyz,Cxyz... which should go into xyz folder."

If they are files you should remove the "/d" switch(match against directories), and of course xcopy should turn into a copy command instead, though copy should work fine with out the for loop.


0

Response Number 4
Name: Remo
Date: September 24, 2009 at 06:03:43 Pacific
Reply:

Thanks a lot! it worked. The number of files did not have anything to do. I realised late that ? means one character. so if xyz_1594 is needed it has to be ???_1594. Anyways thanks a lot for the immediate help.


0

Response Number 5
Name: Judago
Date: September 24, 2009 at 06:08:13 Pacific
Reply:

Yep:

? = one unknown character.
* = one or more unknown characters(sometimes even zero).


1

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Batchfile to copy folders

Batch Job to Copy folders www.computing.net/answers/programming/batch-job-to-copy-folders-/18383.html

VB script to copy folders www.computing.net/answers/programming/vb-script-to-copy-folders/16435.html

Batch file to copy folder www.computing.net/answers/programming/batch-file-to-copy-folder/17404.html