Batch Move files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
danmitch1
Posts: 8
Joined: 26 Oct 2017 13:45

Batch Move files

#1 Post by danmitch1 » 26 Oct 2017 14:11

Hi there , Im new to your forum and am glad to meet you all !

So I have a problem with a huge amount of files I need to move up one level to its parent directory.
I have searched all around but it seems like my issue is unique ( perhaps )

Bascally I have 3 levels of sub folders and I need to eliminate the third .
Image

The third level has multiple folders and each individual folder has a .pdf inside.
So the four subfolders in the picture need to go leaving the pdfs inside the "attendance" folder like this
Image

So what ive been doing is searching with * in the second level, cutting the pdfs out of the third, returning to the second and pasting then deleting the empty third level folders after.
This isnt so bad for one folder but Ive got 1080 folders to go though :shock:

Im not familiar with making my own script but ive seen them in action and they seem super powerful when done right.

Is what im asking doable with one script or do i have to make one for each of the third level sub folders since they all have unique names.

I with I could just select them all and click move to parent directory but thats in a perfect word huh.

Any help is greatly appreciated !
Thanks ,

Dan.

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

Re: Batch Move files

#2 Post by aGerman » 26 Oct 2017 15:23

Try the following script

Code: Select all

@echo off &setlocal
set "folder=C:\wherever\AGTRARAP^ SUGAR MAY^ 777407\Attendance"

for /f "delims=" %%i in ('dir /a-d /b /s "%folder%\*.pdf"') do move "%%~i" "%folder%\"
for /d %%i in ("%folder%\*") do rd /s /q "%%i"

Of course you have to customize variable "folder". NOTE that all of the pdf files have to have unique file names. Batch does not automatically add something like (2) to the file name but simply overwrites a file that has the same name.

Steffen

danmitch1
Posts: 8
Joined: 26 Oct 2017 13:45

Re: Batch Move files

#3 Post by danmitch1 » 27 Oct 2017 06:49

Hi aGerman, Thanks for your reply.

The "folder" varialble represents the root , like the first level l? Here is an example of another file placement
G:\JOB FOLDER\FOLDER1\FOLDER2\EMPLOYEE NAME\SECOND LEVEL\THIRD LEVEL followed by the .PDF

The files names are no problem, ive bulk renamed them with numbering as a suffix.

Here is a clearer view of the file structure.

Image
(sorry for the sideways image.. it uploaded that way..)
So as I said I need to eliminate the 3rd level (orange highlight) so that the pdfs fall in to the second level ( yellow highlight )

Will I have to create a unique script for each of the second level sub folders?

Thanks again for your help,

I really appreciate it !!

Dan.

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

Re: Batch Move files

#4 Post by aGerman » 27 Oct 2017 09:29

The "folder" varialble represents the root

That's how I understood it. Just copy a small section of your original data in order to do some tests.

Steffen

danmitch1
Posts: 8
Joined: 26 Oct 2017 13:45

Re: Batch Move files

#5 Post by danmitch1 » 27 Oct 2017 11:53

So im really not sure what im doing.. :oops:

I created a test file structure.

https://drive.google.com/open?id=0B6L96 ... 3FRVHJEUXc

If you have the time, could you show me what i need to do to obtain my goal?

Thanks a million !

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

Re: Batch Move files

#6 Post by aGerman » 27 Oct 2017 12:10

From where do you want the script to begin searching for the pdf files? From "root" or from "lvl1"?

Steffen

danmitch1
Posts: 8
Joined: 26 Oct 2017 13:45

Re: Batch Move files

#7 Post by danmitch1 » 31 Oct 2017 06:56

Hi , been a bit busy sorry for my late response.

The pdfs from the 3rd level (lvl3 - XX) are the ones I need to move, Im guessing it would need to search there ?

Thanks again for your help !

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

Re: Batch Move files

#8 Post by aGerman » 31 Oct 2017 07:07

That's what I already understood. My question was where the script should start from. In the ZIP example you currently have one subfolder ("lvl1") in "root". Imagine you would have more subfolders (e.g. "foo" and "bar") in "root" and you would let the script start searching from "root" then all pdf files you may have in "foo" and "bar" would have been processed, too.
Again - Do you have several level 1 folders in root that you want to process in the way you described? Or should the script start in the one and only level 1 folder that you have in your example?

Steffen

danmitch1
Posts: 8
Joined: 26 Oct 2017 13:45

Re: Batch Move files

#9 Post by danmitch1 » 31 Oct 2017 07:24

Ohh I think I see what you mean
So yes, In my real files there are several lvl1 subfolders in the root dir. So if i understand correctly, the script needs to search from root and not lvl one.

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

Re: Batch Move files

#10 Post by aGerman » 31 Oct 2017 07:38

Save this code in root.

Code: Select all

@echo off &setlocal
for /d %%i in (*) do for /d %%j in ("%%i\*") do for /d %%k in ("%%j\*") do (
  for %%l in ("%%k\*.pdf") do move "%%l" "%%j\"
  rd /s /q "%%k"
)

Steffen

danmitch1
Posts: 8
Joined: 26 Oct 2017 13:45

Re: Batch Move files

#11 Post by danmitch1 » 31 Oct 2017 09:19

Im not sure im doing it right, I took the the code and pasted it into a notepad and saved it as "testmove.cmd" then I dropped that in the root folder and ran the script but it didnt seem to move any files.

Image

Did I have to add anything to the code?

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

Re: Batch Move files

#12 Post by aGerman » 31 Oct 2017 09:28

Append a PAUSE as last line and see if you get any error messages.
Make sure you saved it ANSI encoded. Or use the script in the attached ZIP.

Steffen
Attachments
testmove.zip
(235 Bytes) Downloaded 313 times

danmitch1
Posts: 8
Joined: 26 Oct 2017 13:45

Re: Batch Move files

#13 Post by danmitch1 » 31 Oct 2017 09:38

YES ! I downloaded the file you attached and it worked like a charm !

You just saved me SOOOOO much time !!!! WOW !!!!

Thanks sooooo much!!!!

I Owe you big time !!!

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

Re: Batch Move files

#14 Post by aGerman » 31 Oct 2017 09:42

Not worth talking about :wink: You're welcome!

Post Reply