Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.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
File Powershell 7zip压缩和删除_File_Powershell_Archive_7zip - Fatal编程技术网

File Powershell 7zip压缩和删除

File Powershell 7zip压缩和删除,file,powershell,archive,7zip,File,Powershell,Archive,7zip,好吧,我还在学习,所以请把我当白痴看待。 我已经从各种来源收集了一个脚本,它将获取文件夹中具有给定扩展名和时间的所有文件,并使用7zip压缩这些文件。 我还想添加一种方法,用于删除成功压缩的文件。 现在,7zip在每个文件后都会返回一条消息:“一切正常”,所以我想可能会有某种方法来获取该消息并将该文件标记为删除 下面是我当前的压缩代码,关于删除过程的任何帮助或提示都将非常棒。 卢卡斯 ####7 zip变量我从下面的链接得到它 #### http://www.7-zip.org/ #7-zi

好吧,我还在学习,所以请把我当白痴看待。 我已经从各种来源收集了一个脚本,它将获取文件夹中具有给定扩展名和时间的所有文件,并使用7zip压缩这些文件。 我还想添加一种方法,用于删除成功压缩的文件。 现在,7zip在每个文件后都会返回一条消息:“一切正常”,所以我想可能会有某种方法来获取该消息并将该文件标记为删除

下面是我当前的压缩代码,关于删除过程的任何帮助或提示都将非常棒。 卢卡斯


####7 zip变量我从下面的链接得到它
#### http://www.7-zip.org/ 
#7-zip的别名
if(-not(测试路径“$env:ProgramFiles\7-Zip\7z.exe”){抛出“$env:ProgramFiles\7-Zip\7z.exe所需”}
设置别名sz“$env:ProgramFiles\7-Zip\7z.exe”
############################################
####变数
#要压缩的文件的位置
$filePath=“D:\temp”
#选择扩展名,使用。*表示所有扩展名
$e=“.pdf”
#选择文件必须处理的天数。
$d=10
#获取文件夹中符合要求的文件
$ed=Get ChildItem-Recurse-Path$filePath |其中对象{{uu.Extension-eq“$e”-和$\uu.CreationTime–lt(Get Date).AddDays(-$d)}
#获取创建每日存档的当前日期
$date1=获取日期-格式为“yyyyMMdd”
#获取要在存档文件夹名称中使用的当前目录
$path=拆分路径$filepath-Leaf
###########################################
############作用
foreach($ed中的文件){
$name=$file.name
$directory=$file.DirectoryName
$zipfile=“$path-$date1.zip”
sz a-tzip“$directory\$zipfile”“$directory\$name”
}
###########脚本结束##########

所以。。。
删除项目
没有帮助吗?我想会的,但我遇到的问题是,我想确保文件在删除之前压缩,并且如果压缩过程失败,它不会被删除。您可以使用
启动过程
调用7zip-等待
。那么,如果它仍然没有效率,你可以使用jobsThanks,我会看一看。
<#  
This script compresses all files with given extension in the set folder
and add to daily archive ".zip" using 7izp.
#>


#### 7 zip variable I got it from the below link 
#### http://www.7-zip.org/ 
# Alias for 7-zip
if (-not (test-path "$env:ProgramFiles\7-Zip\7z.exe")) {throw         "$env:ProgramFiles\7-Zip\7z.exe needed"}
  set-alias sz "$env:ProgramFiles\7-Zip\7z.exe"

############################################
#### Variables 

# The location of the files you want to compress
$filePath = "D:\temp"

# select extension, use .* for all
$e = ".pdf"

# Select in days how old a file must be to be processed.
$d = 10

#get the files in the folder the match requirements
$ed = Get-ChildItem -Recurse -Path $filePath | Where-Object { _.Extension -eq "$e" -and $_.CreationTime –lt (Get-Date).AddDays(-$d) }

#Gets current date for creating daily archive
$date1 = Get-Date -Format "yyyyMMdd"

#Gets current dir for using in archive folder name
$path = Split-Path $filepath -Leaf


###########################################
############Function

foreach ($file in $ed) {
                $name = $file.name
                $directory = $file.DirectoryName
                $zipfile = "$path-$date1.zip"
                sz a -tzip "$directory\$zipfile" "$directory\$name"     
            }

########### END OF SCRIPT ##########