• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 74
  • Last Modified:

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
0
Vicki05
Asked:
Vicki05
  • 4
  • 4
  • 2
  • +2
1 Solution
 
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
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
 
NVITCommented:
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 CEE Solution Guide - CEO Faru Bonon ITCommented:
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 PrewCommented:
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
 
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 PrewCommented:
Glad that was useful, thanks for the feedback.


»bp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now