Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

batch Moving all files in 100s of folders up one folder

I have a small issue. I'm not super fluent in batch scripting but i'm trying to get better. I'm trying to get a script working at my current job that we can use to move all files in the last sub-directory of a parent up one directory.

The need is for moving image sequences delivered with a superfluous sub-directory up one sub-directory for effects workflow

essentially i'm being delivered 100s of image sequences as:

Episode/Footage/shot/resolution/shot.0000001.dpx

I would love a batch script i could move into the "Footage" folder that would parse the shot directories below them and move the image sequences out of the resolution folder and place them directly into the shot folder so the structure would look more like this:

Episode/Footage/shot/shot.0000001.dpx

This batch would need to be reused over many instances and just be robust enough to be reusable regardless of what the extensions on the image sequences are or the naming structure of the subfolders are.

like image 256
user2836139 Avatar asked Oct 01 '13 18:10

user2836139


2 Answers

for /f "delims==" %%i in ('dir /a:d /b') do for /f "delims==" %%f in ('dir "%%i" /a:d /b') do (move "%%i\%%f\*" "%%i"&&rd "%%i\%%f" /s /q)


The * can be replaced with * . * (no spaces) to only grab files.
Use % instead of %% for use on the command line.
This will grab from any dir under Footage. Delete the first for loop and replace all occuences of %%i with shot to only grab from there.

like image 105
cure Avatar answered Sep 20 '22 17:09

cure


#!/bin/bash
mv Episode/Footage/Shot/*/* Episode/Footage/Shot

Or for more Fanciness:

#!/bin/bash
echo "Write the file path:" 
read file_path

mv $file_path/*/* $file_path/

This will ask you what the path is (This is Episodes/Footage/shot in your example) then find all the files in that path and all the files inside them and put them all in the path. You could also modify this if instead of putting the files in the path you want them in a different place you could add:

echo "Write the destination file path:"
read file_path2

in between: read file_path and mv ... and change:

mv $file_path/*/* $file_path

to:

mv $file_path/*/* $file_path2
like image 34
Cnorwood7641 Avatar answered Sep 19 '22 17:09

Cnorwood7641