我有一個文件夾應該包含10個文件。每個文件名稱將會不同(名稱和擴展名),但是,它將包含一個模式。powershell檢查文件目錄
例如。
SomeThing.FILE0.DAT
SomeThing.FILE1.DAT
SomeThing.FILE2.DAT
and so on till
SomeThing.FILE9.DAT
我的腳本目前沒有任何檢查。我手動運行它確保所有文件都存在。
for ($i=0; $i -le 9; $i++)
{
$FileString = "*FILE"+$i+"*"
$MyFileName = Get-ChildItem e:\files -name -filter $($FileString)
}
不過,我需要自動化的過程,所以我想補充檢查,以確保:
a. Total of 10 files exist in that folder
$FC = (Get-ChildItem c:\testing | Measure-Object).Count;
if($FC -eq 10)
{
echo "File Count is correct"
}
else
{
echo "File Count is incorrect"
}
b. Each of the FILEX (X = 0-9) are present
c. Only one instance of each FILEX (X = 0-9) should be present. If multiple instances of FILEX are present, I need to display it on the screen saying that FILEX pattern is repeated multiple times.
我怎樣才能做到這些剩餘的檢查?它看起來簡單,但比較複雜......
我看到你已經爲你的問題的第一部分提供了答案。 b或c你到目前爲止嘗試過任何東西嗎?如果你有,你在哪裏遇到問題? –
不,我無法爲b和c找到東西。任何指針讚賞。幾個月前我開始學習PowerShell。 – DataRiver
在B&C做* *嘗試。本網站不適合人們爲您編寫所有代碼。 – alroc