使用递归搜索所有目录将文件解压缩到与存档相同的文件夹 [英] Extract files to same folder as archive using recursive to search all directories

查看:50
本文介绍了使用递归搜索所有目录将文件解压缩到与存档相同的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 PowerShell 中执行一项自动化任务,该任务使用递归和 7z.exe 实用程序将多个 .tar 存档的内容提取到各自的子文件夹中.

I'm working on an automation task in PowerShell that extracts the contents of several .tar archives to their respective subfolders using recursion and the 7z.exe utility.

我遇到了一个问题,即输出转储到我的工作目录而不是子目录 gci -r 找到了原始 tarball.

Im running into an issue where the output dumps in my working directory instead of the subdirectory gci -r found the original tarball.

到目前为止我有:

    $files=gci -r | where {$_.Extension -match "tar"}
        foreach ($files in $files) {
            c:7z.exe e -y $file.FullName }

感谢有关在循环内设置工作目录的建议或 7z 提示.

Advice on setting the working directory within the loop or 7z tips are appreciated.

推荐答案

我对 powershell 完全一无所知,但是在下载了一个充满子目录(本质上是publisher.title.author.year")的巨大种子后包含一个或多个 zip 文件,解压后每个 zip 文件都包含多文件 rar 文件的一部分,最后组装后包含一个(无用的命名)pdf 文件...

I am totally totally clueless when it comes to powershell, but after downloading an enormous torrent full of subdirectories ("publisher.title.author.year" essentially) each containing one or more zip files, which when unzipped each contained a part of a multi-file rar arhive, and FINALLY once assembled that contained a (uselessly named) pdf file...

所以我想出了这个粗略准备好的脚本来递归到每个子目录中,将 zip 解压缩到该目录中,然后组装 rar 文件并将 pdf 解压缩到该目录中,然后使用目录名称重命名 pdf,然后移动它是一个目录(所以最后我得到了一个充满有意义命名的 pdf 文件的基本目录......

so I came up with this rough and ready script to recurse into each subdirectory, unzip the zips into that directory, then assemble the rar files and extract the pdf into that directory, then rename the pdf with the directory name, and move it up a directory (so by the end I ended up with the base directory full of meaningfully named pdf files...

无论如何 - 就像我说的,我几乎没有任何 powershell 知识,所以我发布这个主要是因为我浪费了两个小时写它(我可以在 python 或 perl 中在 5-10 分钟内完成:P)并且因为如果它是如果我需要的话,我可能会在网上再次找到它,呵呵

anyway - like I said I have literally no powershell knowledge so I'm mainly posting this because I wasted two hours writing it (I could have done it in 5-10 minutes in python or perl :P) and because if it's on the net I might actually find it again if I need to hehe

$subdirs = Get-ChildItem | ?{$_.Attributes -match 'Directory'}
foreach ($dir in $subdirs) {
    cd $dir
    $zip get-childitem | where {$_.Extension -match "zip"}
    C:7z.exe x -y $zip.FullName
    $rar = get-childitem | where { $_.Extension -match "rar"}
    C:7z.exe x -y $rar
    $pwd = get-item .   
    $newname = $pwd.basename+".pdf"
    get-childitem *.pdf | rename-item -newname $newname
    move-item $newname ..
    cd ..
}

这篇关于使用递归搜索所有目录将文件解压缩到与存档相同的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆