Need to move all the files from subfolders to the parent folder using a batch file

Hi All,

I need to move all the files from subfolders to the parent folder using a batch file. I am not sure what the subfolder names could be. Is there a way to do this in a batch file? Can someone please help?

Thanks,
Vicki
Vicki05Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jose Gabriel Ortega CastroCEOCommented:
I have a script on TechNet that match your needs.

https://gallery.technet.microsoft.com/scriptcenter/Copy-Files-from-folderA-to-29710ef9

Let me know if it helped.
0
slightwv (䄆 Netminder) Commented:
Open up a powershell window.  Move to the parent folder you want to start in and try:
 Get-ChildItem -Recurse -Include *.* | Move-Item -Destination e:\junk
0
Vicki05Author Commented:
How can I do this in Dos? I do not wish to use PowerShell as I am not familiar with it?
0
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

slightwv (䄆 Netminder) Commented:
You can probably write a BAT script to do it but not being familiar with something that can do it with two commands and a pipe shouldn't be dismissed.

Do not fear the unknown!  Powershell is INCREDIBLY POWERFUL.  You just need to start using it and it becomes comfortable after a while.
0
NVITEnd-user supportCommented:
Here is a .bat method to do it.
Note:
1. Open a CMD window to run it.
2. It is currently in test mode. To run it for real, remove the ECHO prefixing the MOVE command
3. Existing files will be overwritten.
@echo off
setlocal EnableDelayedExpansion

set RootDir=%1
if (%RootDir%) equ () echo Missing folder name argument&exit /b 1
for /f "tokens=*" %%a in ('dir /a-d /b /s %RootDir%') do (ECHO move /y %%a %RootDir%)
pause

Open in new window


Example:
MoveToRoot.bat "C:\local\test\EE\src"

Open in new window

move C:\local\test\EE\src\2017.11.06 "C:\local\test\EE\src"
move C:\local\test\EE\src\2017.11.07 "C:\local\test\EE\src"
move C:\local\test\EE\src\2017.11.08 "C:\local\test\EE\src"
move C:\local\test\EE\src\oldcmp.20171108-143200.htm "C:\local\test\EE\src"
move C:\local\test\EE\src\ServerUserCALs.txt "C:\local\test\EE\src"

Open in new window

0
Jose Gabriel Ortega CastroCEOCommented:
Then remove the "powershell" tag in your question because you don't want an answer in powershell
1
slightwv (䄆 Netminder) Commented:
I added the Powershell topic because at the time BAT only wasn't a requirement.
0
Bill PrewIT / Software Engineering ConsultantCommented:
Here's a fairly simple BAT approach if you don't have duplicate file names in the various subfolders....

@echo off
for /r "c:\folder" %%F in (*) do move "%%F" "c:\folder"

Open in new window


»bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vicki05Author Commented:
Thanks for all your responses, I will test the batch out. I will try to learn powershell as well. It is the unknown that does scare me.
0
slightwv (䄆 Netminder) Commented:
>>I will try to learn powershell as well. It is the unknown that does scare me.

As with learning anything new:  Start small.  This task should be the perfect time to jump in the shallow end of the pool!
0
Vicki05Author Commented:
Thanks everyone  for your responses and Thanks Bill as always.

Your solution works and it is easy for me to use as well.
0
Vicki05Author Commented:
Great solution, it is so simple and easy to use. As always you have the correct answer.
0
Bill PrewIT / Software Engineering ConsultantCommented:
Glad that was useful, thanks for the feedback.


»bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.