Hi,
I need a small batch file to do some work
MY root directory is H:/wavz&Rex/XYZ
I am having 2000 folders like this
FOLDER 1
A
FOLDER 2
B
FOLDER 3
C
FOLDER 4
D
I wish to move all A,B,C,D etc., folders to root directory XYZ. Kindly help, I am very new to ms-dos even I dont know how to make a batch file. Kindly help me and save my time.
Want to move all subfolders to one level up
Moderator: DosItHelp
Re: Want to move all subfolders to one level up
Untested:
Edit: added the option to accept user input; user chooses whether original folder will be removed or not.
Edit²: added the /e switch to xcopy command.
Code: Select all
@echo off
setlocal enabledelayedexpansion
cd /d H:/wavz&Rex/XYZ
for /f "delims=" %%A in ('dir /b /ad') do (
set fldrname=%%~nA
if not exist "..\!fldrname!" md "..\!fldrname!"
xcopy /s /e /i /h /-y "%%A\*.*" "..\!fldrname!"&&^
set /p "q=!fldrname! was copied successfully. Remove "%%A"? [Y/N] "
if /i [!q!] == [Y] (
rd /s /q "%%A"&&^
echo "%%~nA" removed successfully.||^
echo "%%~nA" was not removed successfully.
)
set q=
)
endlocal
Edit: added the option to accept user input; user chooses whether original folder will be removed or not.
Edit²: added the /e switch to xcopy command.
Last edited by Fawers on 11 Apr 2012 10:07, edited 2 times in total.
Re: Want to move all subfolders to one level up
Hi Fawers,
Thanks for spending ur precious time on this. I checked this batch file. Its working but I found a small problem .
MY root directory is H:/wavz&Rex/XYZ
I am having 2000 folders like this
FOLDER 1
A
FOLDER 2
B
FOLDER 3
C
FOLDER 4
D
When I tried this batch file All my Floder 1, Folder 2, Folder 3,Folder 4 or moving to XYZ without their subdirectories . But I need All Subdirectories to be moved to XYZ without Folder 1,2,3,4. Your help will be appreciated.
Thanks for spending ur precious time on this. I checked this batch file. Its working but I found a small problem .
MY root directory is H:/wavz&Rex/XYZ
I am having 2000 folders like this
FOLDER 1
A
FOLDER 2
B
FOLDER 3
C
FOLDER 4
D
When I tried this batch file All my Floder 1, Folder 2, Folder 3,Folder 4 or moving to XYZ without their subdirectories . But I need All Subdirectories to be moved to XYZ without Folder 1,2,3,4. Your help will be appreciated.
Re: Want to move all subfolders to one level up
ivar75 wrote:When I tried this batch file All my Floder 1, Folder 2, Folder 3,Folder 4 or moving to XYZ without their subdirectories . But I need All Subdirectories to be moved to XYZ without Folder 1,2,3,4. Your help will be appreciated.
Are the subdirectories empty? The xcopy command is set to move subdirectories as well, but only if they are not empty.
Anyways, add the /e switch to the xcopy command.
Code: Select all
xcopy /s /i /h /-y "%%A" "..\!fldrname!"&&^
should look like
Code: Select all
xcopy /s /e /i /h /-y "%%A" "..\!fldrname!"&&^
Tell me the results when you're done.
Edit: I added it manually to the code on my first post. You might want to test the whole code again.
Re: Want to move all subfolders to one level up
This should work if there are no duplicate folder names.
Run it in the folder that contains "folder1" folder2" etc and it will move folders "folder1\a" and "folder2\b" along with all subdirectories to "H:/wavz&Rex/XYZ"
Please test it on a set of sample files and folders first. It worked here in a simple test but you need to sure that it works properly.
Run it in the folder that contains "folder1" folder2" etc and it will move folders "folder1\a" and "folder2\b" along with all subdirectories to "H:/wavz&Rex/XYZ"
Please test it on a set of sample files and folders first. It worked here in a simple test but you need to sure that it works properly.
Code: Select all
@echo off
for /f "delims=" %%a in ('dir /ad /b') do (
for /f "delims=" %%b in ('dir "%%a" /ad /b') do (
move "%%a\%%b" "H:/wavz&Rex/XYZ"
)
)
pause
Re: Want to move all subfolders to one level up
@fewers
Yes folder A,B, are empty. When I put some files in A,B folders . they are working but I need only subdirectories to come out, Tolal Folder 1,2,(inclu A,B) are going up. My intention is just to seperate all A,B folders out.
Thanks for your time
Yes folder A,B, are empty. When I put some files in A,B folders . they are working but I need only subdirectories to come out, Tolal Folder 1,2,(inclu A,B) are going up. My intention is just to seperate all A,B folders out.
Thanks for your time
Re: Want to move all subfolders to one level up
@foxdirve
Its working !! Exactly what I am looking for !! Thank you very much !! Love the forum..........today I used it and It saved me 48 hours of work ....Thank you once again
Its working !! Exactly what I am looking for !! Thank you very much !! Love the forum..........today I used it and It saved me 48 hours of work ....Thank you once again