tags:

views:

199

answers:

1

i need help with batch file for WINRAR pleasee hi i am trying to use winrar to convert all my different folders individually from one location to another.

example:

c:\projects\test 
c:\projects\country 
c:\projects\db 

to

c:\backup\test.rar 
c:\backup\country.rar 
c:\backup\db.rar 

I am trying the following cmd, which works but what it does is that it gets all the folders in the projects folder into the backup

for /f "delims==" %%D in ('DIR C:\projects /A /B /S') do ( 
"C:\Program Files\WinRAR\WinRAR.EXE" m -r "c:\backup\projects.rar" "%%D" 
) 

but this is what it does

c:\backup\project.rar (it does contain all the files if i extract) i want them separetely

can you please help?

+1  A: 

I think you need to change a couple things.

  1. Change /A to /AD to get just the directories.
  2. Remove the /S so you will only get the top-level directories in C:\Projects.
  3. Inside your FOR loop, change the "c:\backup\projects.rar" to C:\Backup\%%D.rar"

WARNING: This code is untested.

FOR /F "DELIMS==" %%D in ('DIR C:\projects /AD /B') DO ( 
  "C:\Program Files\WinRAR\WinRAR.EXE" m -r "C:\Backup\%%D.rar" "%%D" 
)
aphoria
hi thanks for your response, i tried that FOR /F "DELIMS==" %%D in ('DIR C:\projects /AD /B') DO ( "C:\Program Files\WinRAR\WinRAR.EXE" m -r "C:\Backup\%%D.rar" "%%D" ) but it did not work.
Jessie
Hmmm...Are you getting any messages?
aphoria
no it just runs, the black screen comes out, but the files remain in c:\projects and nothing in c:\backup :(
Jessie
just in case these are folders. c:\projects\test\c:\projects\country\ c:\projects\db\
Jessie
Are you running it from Explorer? Open a command prompt and run it from there so the window will still be open after the script finishes.
aphoria
you mean go to start, run, cmd, then in the black screen, paster this command and press enter? i get %%D was unexpected at this time
Jessie
Save it in a file like MyScript.CMD and then open CMD and run MyScript.CMD.
aphoria
i run it that way, the black screen comes out for a second then it closes. The files are still the same.
Jessie
If you open the command prompt and then run your .CMD file, the command prompt window should not go away unless you have an EXIT command in your script. Do you have more code in the .CMD file than the code above?
aphoria
here is what i get: C:\Documents and Settings\JJessie>c:\scripts\MyScript.CMDC:\Documents and Settings\JJessie>FOR /F "DELIMS==" %D in ('DIR C:\projects /AD/B') DO ("C:\Program Files\WinRAR\WinRAR.EXE" m -r "C:\backup\%D.rar" "%D" )C:\Documents and Settings\JJessie>("C:\Program Files\WinRAR\WinRAR.EXE" m -r "C:\backup\country.rar" "country" )C:\Documents and Settings\JJessie>("C:\Program Files\WinRAR\WinRAR.EXE" m -r "C:\backup\db.rar" "db" )C:\Documents and Settings\JJessie>("C:\Program Files\WinRAR\WinRAR.EXE" m -r "C:\backup\test.rar" "test" )
Jessie
C:\Documents and Settings\JJessie>but still it doesn't do anything to the files they remain in c:\projects and C:\backup folder is empty
Jessie
What if you `CD \Projects` before you run the .CMD file?
aphoria
yes!! thank youuu so much, i really apreciate it! i had tried everything. :)
Jessie
I'm glad we figured it out. If you think my answer helped, could you accept it by clicking the check mark? Thank you!
aphoria