Move files from many child dir to parent dir

Microsoft Windows server 2008 standard
October 21, 2009 at 03:10:47
Specs: Windows 7
The Parent Dir is having around 400 Child Dirs. and each Child Dir having many files. I need to move all the files from all the Child Dirs to the Parent Dir at once.

Any help, will be appreciated much.

Prakash


See More: Move files from many child dir to parent dir

Report •


#1
October 21, 2009 at 09:13:01
Here is a simple batch script
save the text in any text editor as a .bat format under all files type, preferred wordpad or notepad.

include the " marks, they are required if the path has any spaces in, most likely will.

REMEMBER, ZIP THE CHILD DIRECTORY IN A ZIP FILE

@echo off
xcopy "path to child dir.zip" "path to parent dir"
Pause>nul

EXAMPLE

@echo off
xcopy "C:\Child.zip" "C:\Parent"
Pause>nul


Report •

#2
October 21, 2009 at 20:28:04
Dear RobJohnB95,

Thanks for your reply.

i'm having the scenario like,

D:\Documents --- parent folder

and it has around 400 Child folders
D:\Documents\f123\
D:\Documents\f653\
D:\Documents\f8972\
D:\Documents\f912\

so, i need to move the files from all the child folder to Parent folder.

Can you please help me in this?

Thanks in advance,
Prakash


Report •

#3
November 11, 2009 at 05:45:22
This will work if you are just trying to move files from a subfolder to the parent directory, it won't move files from within a subfolder of the subfolder, give a test and see if it will work for you. Save it as a .VBS and change the Origin folder.


Set oFSO = CreateObject("Scripting.FileSystemObject")
sOriginFolder = "c:\test"
For Each Folder in oFSO.GetFolder(sOriginFolder).subfolders
For Each sFile In oFSO.GetFolder(Folder).Files
oFSO.MoveFile sfile, sOriginFolder & "\" & sFile.Name
next
next


Report •

Related Solutions

#4
November 11, 2009 at 06:03:30
Or you can do it in a batch file that will copy everything including files in subfolders of subfolders using a batch file like the following, again all you have to change is the path of the originfolder


@Echo off
Set sOriginFolder="c:\test"

For /f "Tokens=*" %%a in ('Dir %sOriginFolder% /a-d /s /b') do (
move "%%a" %sOriginFolder%
)


Report •

#5
November 11, 2009 at 21:05:38
Dear gtaion,

Its a great help. It works fine for me.

Thanks a lot.

Prakash


Report •


Ask Question