WatchDirectory Forum
http://www.watchdirectory.net/cgi-bin/yabb25/YaBB.pl
watchDirectory forums >> How to... >> rename extracted file to parent directory name
http://www.watchdirectory.net/cgi-bin/yabb25/YaBB.pl?num=1399269947

Message started by |Ocubit| on May 5th, 2014 at 8:05am

Title: rename extracted file to parent directory name
Post by |Ocubit| on May 5th, 2014 at 8:05am
Hi I am in a scenario where I have to get a lot of rar files extracted and renamed to the parent directory name. cant figure how to accomplish that. can anyone help me with that.
I know how to extract the files. it is just the renaming where i am lost.


Title: Re: rename extracted file to parent directory name
Post by Gert on May 5th, 2014 at 10:14am
So you extract the rar and then want to rename the rar to the parent dir name?
I am a bit confused.....

Can you ask again with example filenames?

Title: Re: rename extracted file to parent directory name
Post by |Ocubit| on May 5th, 2014 at 1:04pm

|Ocubit| wrote on May 5th, 2014 at 8:05am:
Hi I am in a scenario where I have to get a lot of rar files extracted and renamed to the parent directory name. cant figure how to accomplish that. can anyone help me with that.
I know how to extract the files. it is just the renaming where i am lost.


I have a archive (abcd01.rar) inside that archive there is a file named abcd01.txt

it is located here "g:\ftp\misc\abcd01.rar"

the final goal is to extract the file to this folder with the parent foldername as the filename
g:\ftp\misc\misc.txt






Title: Re: rename extracted file to parent directory name
Post by Gert on May 6th, 2014 at 8:15am
Hi,

That should be possible using the "run a bat file" task. I will write a little script for you, but I have a few more questions...

Do those rar files always have only one file in them?
Does this file inside the rar always have the same base name as the rar?

Title: Re: rename extracted file to parent directory name
Post by |Ocubit| on May 7th, 2014 at 5:06pm
wow that would be great. thumbs up for that.

to answer your queastions...

-there is allways only one file inside the archive and they are allways zipped with RAR.

-the filename inside the rar archive does allways have diffent filenames. but the filename of the rar achive and the file inside the rar archive allways match each other

Title: Re: rename extracted file to parent directory name
Post by Gert on May 8th, 2014 at 6:19am
OK, that should be relatively easy. One final question....

You said earlier

Quote:
(abcd01.rar) inside that archive there is a file named abcd01.txt

I assume this is just an example. It would make the script a lot easier to write if you can tell me what type of files (their extension) are inside the rar. Are they really txt files?

Title: Re: rename extracted file to parent directory name
Post by |Ocubit| on May 8th, 2014 at 10:51am
it's allways .ISO files inside the archives

Title: Re: rename extracted file to parent directory name
Post by Gert on May 8th, 2014 at 12:00pm
Ok, I will write a script for you later today.

Title: Re: rename extracted file to parent directory name
Post by Gert on May 8th, 2014 at 12:29pm
Hi,

Use the "run any bat file" task to run the following script for detected rar files. You may need to change a few directory-names and you need to download a helper tool from http://blog-en.gdpsoftware.com/2013/06/free-program-parse-filename-into.html

The script below is not tested but I think it should run fine.

[code]SET UNRAR=C:\Program Files\WinRAR\unrar.exe
rem see http://blog-en.gdpsoftware.com/2013/06/free-program-parse-filename-into.html for the download below
SET SPLIT=C:\Bin\WDDirSplit.exe


"%UNRAR%" e -y "%WD_FILE%" "%WD_FILE_D%"
if %errorlevel% neq 0 goto :eof

del "%WD_FILE%"
call :determineNewName
ren "%WD_FILE_D%%WD_FILE_B%.ISO" "%NEWNAME%"
GOTO :EOF


:determineNewName
"%SPLIT%" "%WD_FILE%" "C:\Temp\%WD_CUREVT%.BAT"
CALL "C:\Temp\%WD_CUREVT%.BAT"
DEL "C:\Temp\%WD_CUREVT%.BAT"
SET NEWNAME=%WD_DPR_2%.ISO
GOTO :EOF

[/code]

Title: Re: rename extracted file to parent directory name
Post by |Ocubit| on May 10th, 2014 at 9:21am
thanks this is really great and top $ support!
i've just sent an email to my colleague to buy a second license for another server with the same issue.

we will test your script on monday/asap

Title: Re: rename extracted file to parent directory name
Post by |Ocubit| on May 11th, 2014 at 1:06pm
your script seems to work pretty well. i had to ajust it a bit as you mentioned.
thank you very much

maybe this could be a new feature in a future version of watchdirectory  :)

WatchDirectory Forum » Powered by YaBB 2.5.2!
YaBB Forum Software © 2000-2017. All Rights Reserved.