0

It feels like this is a colossally stupid question, but the documentation for rar as a whole is pretty sketchy, and using python to rar pulls an insane number of hits, none of them even seem to be attempting what I'm trying to do (which I find somewhat odd).

I have a directory with a bunch of files: FILE_1.ext FILE_2.ext FILE_3.ext ... FILE_N.ext

The names aren't necessarily uniform, neither are the extensions. I'm looking for a python script to: for all files in directory that don't start with . rar a -m0 -R -v1g FILE_NAME.rar "FILE_NAME" #Note: FILE_NAME.rar doesn't have the ".ext"

The "rar a -m0 -R -v1g FILE_NAME.rar "FILE_NAME"" part is what I use when I'm sending a shell command, for one file, and I have to enter the FILE_NAME myself, etc. Hasn't been a problem, but now I'm dealing with a lot of large files, and it's too much to enter them all in one-by-one, but I need to have each file be it's own volume.

2
  • Any reason you can't use tar/zip? Commented Mar 9, 2012 at 14:01
  • Why Python? I love Python dearly, but this particular problem would be easily solved with a shell script. Commented Mar 9, 2012 at 14:25

1 Answer 1

1

How about:

    import os
    for file_n in os.listdir(DIRECTORY_NAME):
         if not file_n.startswith('.') and not file_n.endswith('.rar'):
              os.system('rar a -m0 -R -v1g %s.rar "%s"' %(os.path.splitext(file_n)[0], file_n))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.