WatchDirectory home page
WatchDirectory Startseite (Deutsche Version)
Site WatchDirectory (Français)
  Welcome, Guest. Please Login or Register
YaBB - Yet another Bulletin Board
   
  HomeHelpSearchLoginRegister  
 
Page Index Toggle Pages: 1
rename extracted file to parent directory name (Read 6962 times)
|Ocubit|
YaBB Newbies
*
Offline



Posts: 6
rename extracted file to parent directory name
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.

Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2225
The Netherlands
Re: rename extracted file to parent directory name
Reply #1 - 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?
Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
|Ocubit|
YaBB Newbies
*
Offline



Posts: 6
Re: rename extracted file to parent directory name
Reply #2 - 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





Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2225
The Netherlands
Re: rename extracted file to parent directory name
Reply #3 - 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?
Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
|Ocubit|
YaBB Newbies
*
Offline



Posts: 6
Re: rename extracted file to parent directory name
Reply #4 - 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
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2225
The Netherlands
Re: rename extracted file to parent directory name
Reply #5 - 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?
Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
|Ocubit|
YaBB Newbies
*
Offline



Posts: 6
Re: rename extracted file to parent directory name
Reply #6 - May 8th, 2014 at 10:51am
 
it's allways .ISO files inside the archives
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2225
The Netherlands
Re: rename extracted file to parent directory name
Reply #7 - May 8th, 2014 at 12:00pm
 
Ok, I will write a script for you later today.
Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2225
The Netherlands
Re: rename extracted file to parent directory name
Reply #8 - 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

 

Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
|Ocubit|
YaBB Newbies
*
Offline



Posts: 6
Re: rename extracted file to parent directory name
Reply #9 - 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
Back to top
 
 
IP Logged
 
|Ocubit|
YaBB Newbies
*
Offline



Posts: 6
Re: rename extracted file to parent directory name
Reply #10 - 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  Smiley
Back to top
 
 
IP Logged
 
Page Index Toggle Pages: 1