코드에 표시된대로 LastWriteTime이 $ lwt 인 특정 원본 폴더의 모든 파일을 반환하려면 ". *"확장명과 일치해야합니다. 사용자는 ".csv"와 같은 특정 확장자를 제공 할 수 있지만 스크립트가 제공되지 않으면 모든 파일을 검색합니다. 하지만 확장명을 ". *"과 일치시켜 모든 파일을 반환 할 수는 없습니다.Powershell 파일 확장자 일치 *
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)][string]$source,
[Parameter(Mandatory=$true)][string]$destination,
[string]$exten=".*",
[int]$olderthandays = 30
)
$lwt = (get-date).AddDays(-$olderthandays)
if(!(Test-Path $source)){
Write-Output "Source directory does not exist."
exit
}
if(!(Test-Path $destination)){
Write-Output "Source directory does not exist."
exit
}
if($olderthandays -lt 0){
Write-Output "You can't provide a negative number of days. If you want everything deleted simply provide 0 for number of days."
exit
}
if(!$exten.StartsWith(".")){
$exten = "."+$exten
$exten
}
try{
Get-ChildItem $source -ErrorAction Stop | ?{$_.LastWriteTime -lt $lwt -AND $_.Extension -eq $exten} | foreach {
Write-Output $_.FullName
# Move-item $_.FullName $destination -ErrorAction Stop
}
}
catch{
Write-Output "Something went wrong while moving items. Aborted operation."
}
어떻게 달성 할 수 있습니까?
"확장명을 '. *'과 일치시키는 것은 무엇을 의미합니까? 그래서, "/Users/foo/Documents/bar.*"의 파일 이름이 일치합니까? 또는. *은 정규식에서 매우 의미가 있기 때문에 다른 것입니다. – RamenChef
확장자가 .csv, .pdf 또는 그와 비슷한 내용을 말합니다. – Junaid