Menu

extract .7z's subdirectories into the folder Z:\New extract

2023-02-18
2023-03-23
  • skyline killer

    skyline killer - 2023-02-18

    I have about 100 folders with different .7z files. I want to extract all the .7z files' subdirectories (skipping the parent directory) into Z://New Extract folder. If files/folders exist, it overwrites without prompting
    Example of now:

        ├───Steven Folder
        │       Steven.7z   (parent folder is Steven and has subdirectories of Pictures and          Resume)
        │
        ├───John Jacobs Folder
        │       John Jacobs.7z   (parent folder is John Jacobs and has subdirectories of             Pictures and reports)
        │
        └───Jay Cloud Folder
                    Jay Cloud .7z
    

    Example of what the new extracted structer would be:

    Pictures 'folder'
    Resumes 'folder'
    Reports 'folder'
    

    Can .7z do this?

     

    Last edit: skyline killer 2023-02-18
  • HITCHER

    HITCHER - 2023-02-21

    I don't think so, but you can solve your problem with batch or bash programming, maybe also by using python or powershell and using the cmdline utility of 7z.

     

    Last edit: HITCHER 2023-02-21
  • skyline killer

    skyline killer - 2023-02-21

    Would you care to help me offline on this.

     
  • HITCHER

    HITCHER - 2023-02-22

    You can first xtract all 7z files into the same temporary folder (tempfolder),
    so first create tempfolder and destfolder, extract there all your Zip files,
    then run this bash program with parameters tempfolder and destfolder.

    #!/bin/bash
    SAVEIFS=$IFS
    IFS=$(echo -en "\n\b")
    
    
    function cp-subf() {
            for file in $(ls "$1" )
            do
                    if [[ -d ${1}/${file} ]]; then
                            echo " ${1}/${file}"
                            cp -r  ${1}/${file}/*  "$2"
    
                    fi
            done
    }
    
    function main() {
            cp-subf "$1" "$2"
    }
    
    main "$1" "$2"
    
    IFS=$SAVEIFS
    

    ./cp-subf ./tempfolder ./destfolder

    After that remove temporary folder.

    It is possible to create another bash program, which travels through your directories to find Zip files, and then xtract them to ./tempfolder automatically.

    should work like this (did not test):

    #!/bin/bash
    SAVEIFS=$IFS
    IFS=$(echo -en "\n\b")
    
    function find7z() {   
        for file in $(ls  "$1")
        do
            if [[ ! -d ${1}/${file} ]]; then
                `echo " ${1}/${file}" | grep -q .7z -`
                if [ $? == 0 ]; then
                    echo " ${1}/${file} is a 7z file"
                    7zz x ${1}/${file} -o "$2"
                fi
            else
                find7z "${1}/${file}" "$2"
            fi
        done
    }
    
    function main() {
        find7z "$1" "$2"
    }
    
    main "$1" "$2"
    
    IFS=$SAVEIFS
    

    ./find7z ./searchfolder ./tempfolder

     

    Last edit: HITCHER 2023-02-22
    • skyline killer

      skyline killer - 2023-03-03

      Don't laugh please...How do I run this in Win 11? This isn't a bat correct? Its bash?

       
      • HITCHER

        HITCHER - 2023-03-03

        So if you want to run this on windows, you will need WSL.
        https://learn.microsoft.com/en-us/windows/wsl/install

         
  • skyline killer

    skyline killer - 2023-03-03

    Thank you Hitcher, let me play with this a little.

     
  • skyline killer

    skyline killer - 2023-03-23

    I finally had time to play with the suggested script, but there were just too many discrepancies within the .7z files. Each .7z file seemed to have a different parent directory so What i have done is extract all 200+ .7z files, cleaned up the directories and removed all previous parent directories and re .7z compressed them using a numeric prefix within their own directory. So what I have now is

    ├───001 Steven Folder
    │       001 Steven.7z  
    │
    ├───002 John Jacobs Folder
    │       002 John Jacobs.7z
    │
    └───003 Jay Cloud Folder
                    003 Jay Cloud .7z
    

    Now that I have everything this way, I only need to extract all .7z files in cronological order autoomatically overwrite into a directory R:/Master Unzipped/
    I would like to do this while keeping the .7 files in their directroy. Is this possible or do I need to have them all in the same directory?

     

    Last edit: skyline killer 2023-03-23

Log in to post a comment.