2016-05-26 6 views
0

I持って特定のファイルを取り出すPowerShellスクリプトで次の文私は正確なファイル名と一緒にそのファイル$strAttachmentのパスをホストするために書くことができますどのようにPowerShellのスクリプトステートメントは、特定のファイルパスを取得するには

$imptext = "E:\imp\old" 

$strAttachment = dir $imptext | sort -prop LastWriteTime | Where-Object {$_.name -like "*Imptextfiles*"} | Where-Object {$_.lastwritetime -gt (Get-Date).AddHours(-1)} | select -last 1 | foreach-object -process { $_.FullName } 

答えて

0

ファイルのディレクトリを取得しますか?ちょうどあなたがまたGet-DirectoryName使用することができSplit-Path cmdlet:

$attachmentDirectory = Split-Path $strAttachment 

を使用します。また

$attachmentDirectory =[System.IO.Path]::GetDirectoryName($strAttachment) 

を、あなたは

$strAttachment = Get-ChildItem $imptext -Filter '*Imptextfiles*' | 
    Where-Object Lastwritetime -gt (Get-Date).AddHours(-1) | 
    sort LastWriteTime | 
    select -last 1 | 
    select -ExpandProperty FullName 
-Filter代わり Where-Object 2の使用)あなたのinitalスクリプトを向上させることができます
関連する問題