User User name Password  
   
Tuesday 19.8.2025 / 04:24
Search AfterDawn Forums:        In English   Suomeksi   På svenska
afterdawn.com > forums > software, operating systems and more > windows - software discussion > need help writing a batch file for the following task:
Show topics
 
Forums
Forums
NEED HELP writing a batch file for the following task:
  Jump to:
 
Posted Message
Page:123Next >
aweathe
Junior Member
_
9. May 2007 @ 08:25 _ Link to this message    Send private message to this user   
Hello,

Does anyone know if it is possible to use a batch file for the following action?:

Decompress a large number of WinRAR files stored in a list of folders and subfolders.

Thanks so much for any help offered! Also, I?m a windows XP user.

Andrew
Advertisement
_
__
Indochine
Senior Member
_
9. May 2007 @ 08:47 _ Link to this message    Send private message to this user   
How are the WinRAR files stored? Ae they all over the place, or are they in subfolders of one folder on on drive, or a mixture? Is it possible to get a list that might look like this -

c:\archive\scripts\script1.rar
c:\archive\scripts\script2.rar
c:\archive\scripts\script3.rar
c:\archive\docs\doc1.rar
c:\archive\docs\doc2.rar
c:\archive\docs\doc3.rar?

I don't mean post it on here, I mean is it theoretically possible? Do you know how to do that?




On m'a dit que je suis nul à l'oral, que je n'peux pas mieux faire !
aweathe
Junior Member
_
9. May 2007 @ 09:39 _ Link to this message    Send private message to this user   
How the WinRAR files are stored:

There is a folder containing about 30 subfolders. In each of these 30 subfolders there is between 5-10 different folders, and in these folders is where the WinRAR files are stored. There are about 1-3 WinRAR files in each of these folders.

As for the list format you suggested. Yes it is possible to get it in that format (I'm just learning batch files and don't think it would be too hard)... However I need the folders in the original format at the end. If the WinRAR files were in the format you suggested then I would just select them all the decompress...
Indochine
Senior Member
_
9. May 2007 @ 09:53 _ Link to this message    Send private message to this user   
Quote:
However I need the folders in the original format at the end. If the WinRAR files were in the format you suggested then I would just select them all the decompress...
So you want to extract the contents of the RAR archives somewhere else, leaving the archive folders as they are?

How about another folder tree whose structure follows the original one, except each rar archive is replaced by a subfolder named after it?





On m'a dit que je suis nul à l'oral, que je n'peux pas mieux faire !

This message has been edited since posting. Last time this message was edited on 9. May 2007 @ 09:57

aweathe
Junior Member
_
9. May 2007 @ 09:56 _ Link to this message    Send private message to this user   
Decompress in the folder they're in now. (in-place)
aweathe
Junior Member
_
9. May 2007 @ 10:02 _ Link to this message    Send private message to this user   
Well it would be most useful to have them decompressed in place... is this possible?
Indochine
Senior Member
_
9. May 2007 @ 10:28 _ Link to this message    Send private message to this user   
In place, somewhere else, it's easy either way (famous last words!)... Do you want to keep the archives or delete them once their contents are extracted?




On m'a dit que je suis nul à l'oral, que je n'peux pas mieux faire !
aweathe
Junior Member
_
9. May 2007 @ 10:35 _ Link to this message    Send private message to this user   
I would like to keep the archives where they are.
Indochine
Senior Member
_
9. May 2007 @ 10:42 _ Link to this message    Send private message to this user   



So the layout is like this?

Spec check...

Are you hoping for a batch file which could be run from Top Folder, which would result in all the RAR contents being extracted to the same sub-sub-folder where they are located? Without deleting the RARs?

Expect trial version tomorrow...




On m'a dit que je suis nul à l'oral, que je n'peux pas mieux faire !
aweathe
Junior Member
_
9. May 2007 @ 10:45 _ Link to this message    Send private message to this user   
Yes that's the folder structure exactly! And "yes" is the answer to your last two questions. ie: I would like to keep the archives in the same place and have them extracted in the same place.

Thanks! I'll just wait for your post!
aweathe
Junior Member
_
9. May 2007 @ 10:58 _ Link to this message    Send private message to this user   
and also the file can be run from the Top folder in the diagram you posted.
Indochine
Senior Member
_
9. May 2007 @ 12:13 _ Link to this message    Send private message to this user   
I am presuming that you have Rar.exe, the command-line program that comes along with WinRAR, and that its location is

C:\Program Files\WinRAR\Rar.exe

The version number would be helpful


C:\Program Files\WinRAR>rar /?
RAR 3.70 beta 1   Copyright (c) 1993-2007 Alexander Roshal   8 Jan 2007
Registered to Mike
(etc)



On m'a dit que je suis nul à l'oral, que je n'peux pas mieux faire !

This message has been edited since posting. Last time this message was edited on 9. May 2007 @ 12:16

aweathe
Junior Member
_
9. May 2007 @ 13:43 _ Link to this message    Send private message to this user   
Yes the directory where WinRAR is located is correct. my version is 3.62, but could download a more recent one if necessary. I have only the evaluation copy as well.
Indochine
Senior Member
_
10. May 2007 @ 02:56 _ Link to this message    Send private message to this user   
copy this to Notepad & save as a batch file in the "Top folder" we discussed earlier.

@echo off
REM place this batch file in the top folder
REM and run it from there
if exist "%temp%\rardirlist.txt" del "%temp%\rardirlist.txt" > nul
if exist "%temp%\subdirlist.txt" del "%temp%\subdirlist.txt" > nul

REM remember where we are
set topfolder=%CD%

REM get a list of all the subfolders
REM under this one and put it in
REM a temp file
dir /b /s /ad > "%temp%\subdirlist.txt"

REM in a loop check each one for presence of
REM rar files, write folder name to another list
REM if any found
for /F "delims==" %%a in (%temp%\subdirlist.txt) do (
	cd %%a
	if exist *.rar echo %%a >> "%temp%\rardirlist.txt"
	)

REM for each folder that contains RARs
REM cd to that folder and extract
for /F "delims==" %%a in (%temp%\rardirlist.txt) do (
	cd %%a
	"c:\program files\winrar\rar.exe" e *.rar
	)

REM clean up
del "%temp%\subdirlist.txt" > nul
del "%temp%\rardirlist.txt" > nul

REM go back to where we were
cd %topfolder%




On m'a dit que je suis nul à l'oral, que je n'peux pas mieux faire !

This message has been edited since posting. Last time this message was edited on 10. May 2007 @ 03:22

aweathe
Junior Member
_
10. May 2007 @ 06:48 _ Link to this message    Send private message to this user   
unfortunately it didn't work on the first trial... hmmm I'm reading it and trying to figure it out so that I can fix it, but I'm just not there yet in the understanding!

Maybe this with clarify; I have copied the output that I recieved in the command promt after running the file from there. (I named your file "winRAR.bat"). OK here it is:


C:\Documents and Settings\ANDREW\Desktop\Assign 1>winRAR.bat
The system cannot find the file C:\DOCUME~1\ANDREW\LOCALS~1\Temp\rardirlist.txt.

Could Not Find C:\DOCUME~1\ANDREW\LOCALS~1\Temp\rardirlist.txt

C:\Documents and Settings\ANDREW\Desktop\Assign 1>
Indochine
Senior Member
_
10. May 2007 @ 06:57 _ Link to this message    Send private message to this user   
try this... creates and destroys temp files in the TOP folder



@echo off
REM place this batch file in the top folder
REM and run it from there

if exist "rardirlist.txt" del "rardirlist.txt" > nul
if exist "subdirlist.txt" del "subdirlist.txt" > nul

REM remember where we are
set topfolder=%CD%

REM get a list of all the subfolders
REM under this one and put it in a temp file
dir /b /s /ad > "subdirlist.txt"

REM in a loop check each one for rar files
REM write folder name to another list if any found
for /F "delims==" %%a in (subdirlist.txt) do (
cd %%a
if exist *.rar echo %%a >> "rardirlist.txt"
)

REM for each folder that contains RARs
RE enter folder and extract
for /F "delims==" %%a in (rardirlist.txt) do (
cd %%a
"c:\program files\winrar\rar.exe" e *.rar
)

REM clean up
del "subdirlist.txt" > nul
del "rardirlist.txt" > nul

REM go back to where we were
cd %topfolder%




On m'a dit que je suis nul à l'oral, que je n'peux pas mieux faire !
aweathe
Junior Member
_
10. May 2007 @ 07:16 _ Link to this message    Send private message to this user   
I'm looking over this myself right now... but here's the error message I got this time in the cmd promt (this time your file is labeled "winRAR2.bat" :


C:\Documents and Settings\ANDREW\Desktop\Assign 1>winRAR2.bat
'RE' is not recognized as an internal or external command,
operable program or batch file.
The system cannot find the file rardirlist.txt.
Could Not Find C:\Documents and Settings\ANDREW\Desktop\Assign 1\9-Dec-2006\I57U
S\subdirlist.txt
Could Not Find C:\Documents and Settings\ANDREW\Desktop\Assign 1\9-Dec-2006\I57U
S\rardirlist.txt

C:\Documents and Settings\ANDREW\Desktop\Assign 1>
aweathe
Junior Member
_
10. May 2007 @ 07:22 _ Link to this message    Send private message to this user   
Oh and I fixed the "RE" to "REM"
aweathe
Junior Member
_
10. May 2007 @ 07:27 _ Link to this message    Send private message to this user   
I'm not sure of the difference (or if it matters) but it's written ">>" instead of ">" about halfway down the script.
Indochine
Senior Member
_
10. May 2007 @ 07:41 _ Link to this message    Send private message to this user   
yes, >> appends to file if it already exists, or creates a new one if it doesn't, whereas > always creates a new one.

Getting there!


On m'a dit que je suis nul à l'oral, que je n'peux pas mieux faire !
Indochine
Senior Member
_
10. May 2007 @ 07:52 _ Link to this message    Send private message to this user   
This is a debugging version with lots of messages and progress updates...


@echo off
REM place this batch file in the top folder
REM and run it from there

REM remember where we are
set topfolder=%CD%

if exist "%topfolder%\subdirlist.txt" del "%topfolder%\subdirlist.txt" > nul
if exist "%topfolder%\rardirlist.txt" del "%topfolder%\rardirlist.txt" > nul
echo.
echo (1) creating list of all sub folders...
echo.

REM get a list of all the subfolders
REM under this one and put it in a temp file
dir /b /s /ad > "%topfolder%\subdirlist.txt"

echo all sub folders...
echo.
type "%topfolder%\subdirlist.txt"
echo.
pause
echo.
echo (2) finding folders with rars in them
echo.

REM in a loop check each one for  rar files
REM write folder name to another list if any found
for /F "delims==" %%a in ('type "%topfolder%\subdirlist.txt"') do (
	cd %%a
	if exist *.rar echo %%a >> "%topfolder%\rardirlist.txt"
	)

echo all sub folders with Rars in...
echo.
type "%topfolder%\rardirlist.txt"
echo.
pause
echo.
echo (3) extracting from Rar archives
echo.
echo ready to start...
echo.
pause
echo.
REM for each folder that contains RARs
REM enter folder and extract
for /F "delims==" %%a in ('type "%topfolder%\rardirlist.txt"') do (
	echo.
	echo expanding rars in %%a
	echo.

	cd %%a
	"c:\program files\winrar\rar.exe" e *.rar
	)

REM clean up
rem del "%topfolder%\subdirlist.txt" > nul
rem del "%topfolder%\rardirlist.txt" > nul

REM go back to where we were
cd %topfolder%
echo.
echo (4) Finished
echo.
pause
echo.




On m'a dit que je suis nul à l'oral, que je n'peux pas mieux faire !

This message has been edited since posting. Last time this message was edited on 10. May 2007 @ 07:52

aweathe
Junior Member
_
10. May 2007 @ 08:40 _ Link to this message    Send private message to this user   
I'm working through it. Almost works I think... going to have to take a break for lunch tho! Thanks so much for the help. I'll write you again when I solve it or if I get stuck.

Just a couple (simple) questions so that I can understand the code and make it work:
1. "for /F" means for all folders in the current directory?
2. "dir /b /s /ad" : in this statement I believe "/s" means include all subfolders, however I don't understand "/b" and "/ad".

Finally, the part of the code that has the problem is copied here:
""
REM in a loop check each one for rar files
REM write folder name to another list if any found
for /F "delims==" %%a in ('type "%topfolder%\subdirlist.txt"') do (
cd %%a

if exist *.rar echo %%a > "%topfolder%\rardirlist.txt"
)
""
The problem is that the folder "rardirlist.txt" doesn't get created...?

talk to you again soon...
Indochine
Senior Member
_
10. May 2007 @ 09:20 _ Link to this message    Send private message to this user   
Originally posted by aweathe:
1. "for /F" means for all folders in the current directory?

Putting /F after the FOR indicates to FOR that whatever is between the parentheses is the source of a series of lines of data to be read and processed. Single quotes around what is in the parentheses indicate that the source is the output of a command.

In this line,

for /F "delims==" %%a in ('type "%topfolder%\subdirlist.txt"') do (

FOR is told to TYPE the file and deal with it line by line.

* without the "/f", what is between the parentheses is interpreted as a series of ITEMS.

for "delims==" %%f in (apple orange banana) do (
echo %%f
)

the result would be

apple
orange
banana

* single-quotes within the parentheses indicates that the data lines are sourced from the output of a command. Without the single-quotes, FOR /F tries to read a (text-)file named (whatever is within the parentheses)

2. "dir /b /s /ad" : in this statement I believe "/s" means include all subfolders, however I don't understand "/b" and "/ad".

Dir /? will give full info.

Dir /b gives a bare output, just the file names, no date or size info or header or footer. Necessary for processing in batch files.

Dir /ad --- /(a)ttribute (d)irectory just finds directories.
Dir /ah --- /(a)ttribute (h)idden finds just hidden files
Dir /ar --- /(a)ttribute (r)ead only finds just read only files
Dir /as --- /(a)ttribute (s)ystem finds just system files.

A minus sign eg dir /a-d inverts the effect.

Quote:

Finally, the part of the code that has the problem is copied here:
""
REM in a loop check each one for rar files
REM write folder name to another list if any found
for /F "delims==" %%a in ('type "%topfolder%\subdirlist.txt"') do (
cd %%a

if exist *.rar echo %%a > "%topfolder%\rardirlist.txt"
)
""
The problem is that the folder "rardirlist.txt" doesn't get created...?

Does subdirlist.txt get created?

Until our next chat...

On m'a dit que je suis nul à l'oral, que je n'peux pas mieux faire !
Indochine
Senior Member
_
10. May 2007 @ 10:28 _ Link to this message    Send private message to this user   
New greatly simplified version - no temp files, it just goes ahead and does it.

[original post 14:28 hrs updated 20:20 hrs]


@echo off
REM place this batch file in the top folder and run it from there
set topfolder=%CD%
for /F "delims==" %%a in ('dir /b /s *.rar') do (
 	cd "%%~Da%%~pa"
	"c:\program files\winrar\rar.exe" e "%%~Da%%~pa%%~nxa" | findstr "Extracting from"
	)
cd %topfolder%



On m'a dit que je suis nul à l'oral, que je n'peux pas mieux faire !

This message has been edited since posting. Last time this message was edited on 10. May 2007 @ 11:21

Advertisement
_
__
 
_
aweathe
Junior Member
_
10. May 2007 @ 12:13 _ Link to this message    Send private message to this user   
RE:
Quote:
Does subdirlist.txt get created?
yes it does. and it looks fine.
 
Page:123Next >
afterdawn.com > forums > software, operating systems and more > windows - software discussion > need help writing a batch file for the following task:
 

Digital video: AfterDawn.com | AfterDawn Forums
Music: MP3Lizard.com
Gaming: Blasteroids.com | Blasteroids Forums | Compare game prices
Software: Software downloads
Blogs: User profile pages
RSS feeds: AfterDawn.com News | Software updates | AfterDawn Forums
International: AfterDawn in Finnish | AfterDawn in Swedish | AfterDawn in Norwegian | download.fi
Navigate: Search | Site map
About us: About AfterDawn Ltd | Advertise on our sites | Rules, Restrictions, Legal disclaimer & Privacy policy
Contact us: Send feedback | Contact our media sales team
 
  © 1999-2025 by AfterDawn Ltd.

  IDG TechNetwork