Her dosya için bir dosya oluşturulduğunda her bir döngü için bir komut kümesi ayarlıyorum. Döngüde bir dosya başka bir klasöre taşınır ve aynı dosyanın 3 kez taşınması gerekiyorsa, dosyayı farklı bir tabloya taşır ve kayıt tablosunu hash tablosundan kaldırır.Powershell - Script her döngü için girilmiyor
Sorunum, komut dosyasını çalıştırdığımda, her döngü için yazdığım her şeyi yapmadığıdır. Sadece üstünde senaryo yazıyorsam. Birisi size tavsiyede bulunabilir mi?
$folder = 'C:\Users\jnwankwo\Documents\IUR Test\r' # Enter the root path you want to monitor.
$Failedfolder = 'C:\Users\jnwankwo\Documents\IUR Test\r'
$filter = '*.*' # You can enter a wildcard filter here.
$Files = @{}
$Counter = 1
$folder = 'C:\Users\jnwankwo\Documents\IUR Test\r' # Enter the root path you want to monitor.
$Failedfolder = 'C:\Users\jnwankwo\Documents\IUR Test\r'
$filter = '*.*' # You can enter a wildcard filter here.
$Files = @{}
$Counter = 1
# In the following line, you can change 'IncludeSubdirectories to $true if required.
$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action {
ForEach ($file in $folder)
{
$fName = $file.Name
if (-not $Files.ContainsKey($fName))
{
$Files.Add($fName,$Counter)
}
if (($Files.ContainsKey($fName)) -and ($Files.Item($fName) -lt 3))
{
Move-Item 'C:\Users\jnwankwo\Documents\IUR Test\r\*.txt' 'C:\Users\jnwankwo\Documents\IUR Test' -force
$Files.Set_Item($fName,$Counter++)
}
ElseIf (($Files.ContainsKey($fName)) -and ($Files.Item($fName) -eq 3))
{
$Files.clear()
Move-Item 'C:\Users\jnwankwo\Documents\Failed\' $Failedfolder -force
}
}
}
# To stop the monitoring, run the following commands:
# Unregister-Event FileCreated
Ne '$ dosyadan veri var sağlayacak gerekir? – PetSerAl
klasör değişkenini betik bloğu dışında bildirirsiniz ve '' $ folder' komut dosyası içinde boş olduğundan ($ counter' ve '$ Files' için de aynısı geçerlidir) argüman olarak aktarmazsınız. parametre olarak iletin veya scriptblock içinde ilan edin, ayrıca @AgentK ne yazdı – Paul
Ne yazdığını gösterebilir misiniz? Ben şimdiye kadar farklı bir sonuç alamıyorum. – Hitmand