Batch Unzip, unzip, unzip, rename folder, rename file, move

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mikelarmer
Posts: 1
Joined: 21 Aug 2015 13:24

Batch Unzip, unzip, unzip, rename folder, rename file, move

#1 Post by mikelarmer » 21 Aug 2015 13:48

Hi

I have a number of files that I get each day in the following format

E:\Test\DATE-Name-IDNumber.zip
E:\Test\DATE-Name2-IDNumber.zip
E:\Test\DATE-Name3-IDNumber.zip

Within each of the files I get additional files, which are also zipped depending on what information they contain ie.

Name-LonglongIDNumber-Left.zip
Name-LonglongIDNumber-Right.zip
Name-LonglongIDNumber-bottom.zip
Name-LonglongIDNumber-top.zip

Within those zipped files I get the file I actually want, however, they are always named the same.. sometimes they are .obj, sometimes they are .jpg, sometimes I get both.

model.obj
model.jpg

So to sum it up, the file I want is the model.obj or model.jpg. Located at -> DATE-Name-IDNumber.zip\Name-LonglongIDNumber-Left.zip\model.obj
What I would like to do is unzip all the zipped folders, and then rename the model to the last zipped folder that it was in, then move the renamed file to the original root folder and delete the subfolders

This is the code I've used to unzip all the folders and try to rename the files.. the problem I've encountered is the file names are now too long with the whole IDnumber included.. I need a way to truncate the folder name to include the date and name - which are always varying lengths due to being names and to keep the last few (5) letters of the folder to keep ie. - left, right, top. I need the files to be named to match the truncated folder(ideally and moved back to the original root folder E:\Test\

for /R "E:\Test" %%I in ("*.zip") do (
"%ProgramFiles(x86)%\7-Zip\7z.exe" x -y -o"%%~dpnI" "%%~fI"
)
@Echo OFF

FOR /D /R %%# in (*) DO (
PUSHD "%%#"
FOR %%@ in ("model*") DO (
Echo Ren: ".\%%~n#\%%@" "%%~n#%%~x@"
Ren "%%@" "%%~n#%%~x@"
)
POPD
)

What I need is the first folder to be unzipped. Then the second folder to be unzipped. - the problem is the final files aren't being renamed to match the previous folder because the folder name is too long?(I think so anyways) What I need help with is truncating the folder, and renaming the file accordingly.. (I can get this to work with folders that are shorter named.) Then after this I have the next project of moving the files to the root E:\Test folder and deleting all the unzipped subfolders.

Post Reply