Find the answer to your Linux question:
Results 1 to 4 of 4
Hi friends! I've fixed an tarball damaged and now obtain many file with the same name into; I tried to create a script based on a previous originally based on ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2010
    Posts
    2

    Lightbulb script extract tar file containg file same name


    Hi friends!

    I've fixed an tarball damaged and now obtain many file with the same name into;

    I tried to create a script based on a previous originally based on the "zipfile" module:

    original:

    Code:
    #!/usr/bin/env python
    import os
    import sys
    import tarfile
    
    count = 0
    
    t = tarfile.TarFile(sys.argv[1],"r")
    
    for info in t.infolist():
        directory = str(count)
        os.makedirs(directory)
        t.extract(info,directory)
        count += 1
    
    t.close()
    modified:

    Code:
    #!/usr/bin/env python
    
    import os
    import sys
    import tarfile
    
    count = 0
    
    t = tarfile.TarFile(sys.argv[1],"r")
    
    for info in t.infolist():
        directory = str(count)
        os.makedirs(directory)
        t.extract(info,directory)
        count += 1
    
    t.close()

    but obtain error becouse the tarfile has not the attribute "infolist"

    how i could change correctly the script for the tarfile module?

    many many thanks!

  2. #2
    Linux Engineer Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    773
    The first and the second code sample are basically the same, except some whitespaces? Have you mis-posted something?

  3. #3
    Just Joined!
    Join Date
    Sep 2010
    Posts
    2
    Hoops! Sorry, this is the unmodified script:

    Code:
    #!/usr/bin/env python
    
    import os
    import sys
    import zipfile
    
    count = 0
    
    z = zipfile.ZipFile(sys.argv[1],"r")
    
    for info in z.infolist():
        directory = str(count)
        os.makedirs(directory)
        z.extract(info,directory)
        count += 1
    
    z.close()

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Engineer Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    773
    well, tar and zip files are handled differently in python. what I mean is, that the python api simply differs. you'll have to adapt the script a bit more than that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •