Batchfile to copy folders

September 24, 2009 at 04:27:20
Specs: Windows XP
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

See More: Batchfile to copy folders

Report •


#1
September 24, 2009 at 04:49:36
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]


Report •

#2
September 24, 2009 at 05:23:46
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.

Report •

#3
September 24, 2009 at 05:39:40
"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.


Report •

Related Solutions

#4
September 24, 2009 at 06:03:43
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.

Report •

#5
September 24, 2009 at 06:08:13
Yep:

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


Report •


Ask Question