Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
DotNetZip、Powershell和相关路径_Powershell_Dotnetzip - Fatal编程技术网

DotNetZip、Powershell和相关路径

DotNetZip、Powershell和相关路径,powershell,dotnetzip,Powershell,Dotnetzip,我只想将一些选定文件夹压缩到具有其相对路径的存档中 其中一些具有相同的文件夹名称(所有版本文件夹、所有调试文件夹) 过滤工作正常,我在获取子对象之前调用了set location命令 做这项工作最简单的方法是什么 我真的需要实现这样的东西吗 foreach ($o in $children) { $relPath = $o.FullName.Substring(subPath.Length); $relPath = $relPath.Substring(0, relPath.Last

我只想将一些选定文件夹压缩到具有其相对路径的存档中

其中一些具有相同的文件夹名称(所有版本文件夹、所有调试文件夹)

过滤工作正常,我在获取子对象之前调用了set location命令

做这项工作最简单的方法是什么

我真的需要实现这样的东西吗

foreach ($o in $children)
{   $relPath = $o.FullName.Substring(subPath.Length);
    $relPath = $relPath.Substring(0, relPath.LastIndexOf(@"\"));
    zip.AddFolder($o.Name, $relPath);
} 
有人能给我举个例子吗


Thx

当我需要处理相对路径时,我会这样做:

$basePath = "C:\MyBasePath"
$newBasePAth = "C:\NewBasePath"

$files = Get-ChildItem $basePath
$newFileNames = foreach ($f in $files) {
    $f.Fullname.Replace($basePath, $newBasePath)
}
确保在$basePath和$newBasePath中使用的斜杠模式相同(请使用.Trim()确保)


希望这有帮助

我终于实现了这一点,并且它与相关路径一起工作:

function ZipUp-Files ( $mychildren )
{
  foreach ($o in $mychildren) 
  {
        $e= $zipfile.AddDirectory($o.FullName,$o.fullname.substring($pwd.path.length));
  }
}

$children =get-childitem -recurse -force | where-object {$_.psiscontainer} | where {$_.name -match $teststring} 

[System.Reflection.Assembly]::LoadFrom("C:\dotNetZip\zip-v1.9\Release\Ionic.Zip.dll");
$zipfile =  new-object Ionic.Zip.ZipFile($ziptarget);
$zipfile.UseZip64WhenSaving= [Ionic.Zip.Zip64Option]::Always
$zipfile.MaxOutPutSegmentSize=734003200
ZipUp-Files $children
$zipfile.Save("c:\temp\arc_rel.zip")
$zipfile.Dispose()

如果你能给出一些你想做的具体例子,那就好了。问题很模糊,我想选择一些特殊的文件(或文件夹)和它们的相对路径一起包含在zip存档中。我正在尝试使用DotNetZip执行此操作。我希望选择要包含在zip存档中的特殊文件(或文件夹),并将其相对路径设置为使用“设置位置”设置的路径。我正试图用DotNetZip做这件事。但总有一条完整的道路。所以我需要提取第一部分(就像winzip自动提取一样)。另一个问题是,当我包含完整的文件夹时。它们中的一些名称相同,但路径不同,我无法按名称添加第二个文件夹。实际上,在这种情况下,您应该使用现有模块,而不是编写自己的模块。听起来您在包装DotNetZip和创建自己的提取命令时遇到了问题。您可以查看PowerShellPack(其中包括Copy-ToZip,可执行此操作)或PowerShell社区扩展(PSCX),后者包括更通用的扩展归档(可执行.7z、.zip、.gzip、.iso等操作)