Search code examples
pythonrarunrar

How to acquire extracted directory using pyUnrar2?


I'm using pyUnrar2 to batch extract rar files, what I would like to acquire is the name of the directory that the files reside in once extracted ?


Solution

  • Extract path is set as an argument to extract().

    If an archive have its own parent directory, you can grab it by using infolist():

    import UnRAR2
    
    rarc = UnRAR2.RarFile('test.rar')
    list = rarc.infolist()
    
    if list[0].isdir:
        print 'Parent directory in archive: %r' % list[0].filename