Move all files up one directory

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mrwonker
Posts: 11
Joined: 21 Apr 2012 11:56

Move all files up one directory

#1 Post by mrwonker » 04 Mar 2021 05:04

Hello, I hope someone can help, I'd like to create a script to be run from "Main Directory" to move any files three subdirectories below up one level, this needs to be able to use a method of wildcards for directories as there are many constantly changing directories, the "Main Directory" itself is also a variable I just wish to be able to move script to this directory and run from there. there are potentialy other files in other directories that don't want to be moved, to demonstrate...

Main Directory/ Random folder jhi/ Random folder jgy/ Random folder jhi/ files that want to be moved to Random folder jgy (up one level)
Main Directory/ Random folder mnu/ Random folder rts/ Random folder pih/ files that want to be moved to Random folder rts (up one level)
Main Directory/ Random folder aft/ Random folder tfg/ Random folder kjk/ files that want to be moved to Random folder tfg (up one level)
Main Directory/ Random folder kje/ Random folder wth/ Random folder pyt/ files that want to be moved to Random folder wth (up one level)

Thanks in advance to any help you may be able to offer.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Move all files up one directory

#2 Post by aGerman » 04 Mar 2021 15:17

If I don't miss something, that should do the trick:

Code: Select all

@echo off
for /d %%a in (*) do for /d %%b in ("%%a\*") do for /d %%c in ("%%b\*") do for %%d in ("%%c\*.*") do ECHO move "%%d" "%%b\"
PAUSE
This doesn't move anything yet, it just prints the command lines to the screen. Remove both ECHO and PAUSE if the right files and target folders are displayed.

Steffen

mrwonker
Posts: 11
Joined: 21 Apr 2012 11:56

Re: Move all files up one directory

#3 Post by mrwonker » 04 Mar 2021 17:48

:D :D :D :D :D :D
Thanks Steffen, I knew it would be a pretty simple batch, spent hours trying to figure it out to no avail, you've saved me so much time, very much appreciated.

Post Reply