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

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

问题描述

我正在执行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中,找到了原始的压缩文件。

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。文件,每个文件解压缩后都包含一个多文件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文件s ...

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知识,所以我主要发布此内容是因为我浪费了两个小时来编写它(我本可以做到的在5到10分钟内使用python或perl: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天全站免登陆