Aktywne Wpisy
![ZenujacaDoomerka](https://wykop.pl/cdn/c0834752/a1bec52f9854568b9e6752e4bd1c9ae13abf69fcc780f6488fad64a6f553e343,q60.jpg)
ZenujacaDoomerka +19
![ZenujacaDoomerka - Zakochałam się w postaci komputerowej (╥﹏╥) czemu żywi mężczyźni ...](https://wykop.pl/cdn/c3201142/377807702024a5c1f8406b006c785280db7864d1ee0f7116a34703f7c7d4dc7a,w150.jpg?author=ZenujacaDoomerka&auth=eee5c0128762352b70c50532ddf43374)
źródło: 1000015497
Pobierz
zbigniew23 +60
![zbigniew23 - Stan zdrowia Zera
#heheszki #bekazprawakow](https://wykop.pl/cdn/c3201142/ab3bbe5490681aa6050a7cabf0d922ee9a16bcfa5ac43deb30dfa5a16c2c0c63,w150.jpg?author=zbigniew23&auth=4a5163264db8cf7ee84f5c606bb74433)
źródło: temp_file5714635529489345839
PobierzSkopiuj link
Skopiuj linkźródło: 1000015497
Pobierzźródło: temp_file5714635529489345839
PobierzWykop.pl
#Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
Set-ExecutionPolicy Unrestricted -Scope Process -Force
$folder = 'D:\WebApp\Dane_otrzymane\' #folder z ktorego jest kopiowany plik przeslany przez komputer WAGA
$filter = '*.txt'
$destination = 'D:\WebApp\htdocs\mysql' #folder do którego jest kopiowany i zaciagany do naszej bazy danych u nas to
$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{
IncludeSubdirectories = $true
NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'
}
$onCreated = Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action {
#create copy of file
Copy-Item $folder 'D:\WebApp\htdocs\mysql\Kopia' -Recurse -Force
#move file
$path = $Event.SourceEventArgs.Fullpath
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "The file '$name' was $changeType at $timeStamp"
Move-Item $path -Destination $destination -Force -Verbose
#start MySQL Querry
Start-Process -FilePath "D:\Skrypty\LOAD.bat" -Verb runAs -Wait -PassThru;$a.ExitCode
}
$filter2 = '*.jpg'
$destination2 = 'D:\WebApp\htdocs\www\img'
$fsw2 = New-Object IO.FileSystemWatcher $folder, $filter2 -Property @{
IncludeSubdirectories = $true
NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'
}
$onCreated2 = Register-ObjectEvent $fsw2 Created -SourceIdentifier FileCreated2 -Action {
$path2 = $Event.SourceEventArgs.Fullpath
$name2 = $Event.SourceEventArgs.Name
$changeType2 = $Event.SourceEventArgs.ChangeType
$timeStamp2 = $Event.TimeGenerated
Write-Host "The file '$name2' was $changeType2 at $timeStamp2"
Move-Item $path2 -Destination $destination2 -Force -Verbose
}
#powershell #programowanie
Mam taki pomysł może zrobić to w pętli do while? I działać dodatkowo Unregister-Event dla dwóch tych Register-ObjectEvent?
Wtedy będzie występowało odświeżanie Eventu jakby?
Może uruchamiać powershella raz na dobę np o 12 i wtedy byłoby pewniejsze? W taskschedulerze
Jak utworzyłem Register-ObjectEvent na IO.FileSystemWatcher to przenosi mi tlyko pliki które są utworzone podczas jego działania. Dokładnie jeden plik .txt który jest nadpisywany dopóki go nie zabiorę z tamtąd. I w przypadku wyłączenia skryptu na 2 minuty o północy, jeżeli coś powstanie gdy jest nieaktywny to
źródło: comment_YOXTbhsTs2DYeCV9NqhOCgXkP3wXuqWQ.jpg
Pobierz