Powershell wait for file to delete, then copy a folder
Posted
by
user3317623
on Stack Overflow
See other posts from Stack Overflow
or by user3317623
Published on 2014-06-12T00:09:05Z
Indexed on
2014/06/12
3:25 UTC
Read the original article
Hit count: 123
Morning guys,
I have a couple of scripts that have to sync a folder from the network server, to the local terminal server, and lastly into the %LOCALAPPDATA%. I need to first check if a folder is being synced (this is done by creating a temporary COPYING.TXT on the server), and wait until that is removed, THEN copy to %LOCALAPPDATA%.
Something like this:
- Server-side script executes, which syncs my folder to all of my terminal servers.
- It creates a COPYING.TXT temporary file, which indicates the sync is in progress. Once the sync is finished, the script removes the COPYING.TXT
If someone logs on during the sync, I need a script to wait until the COPYING.TXT is deleted I.E the sync is finished, then resume the local sync into their %LOCALAPPDATA%.
do{cp c:\folder\program $env:LOCALAPPDATA} while(!(test-path c:\folder\COPYING.txt))
(So that copies the folder while the file DOESN'T exist, but I don't think that exits cleanly)
I cannot format the above as code for some reason I'm sorry?
Or:
while(!(test-path c:\folder\COPYING.txt)){
cp c:\folder\program $env:LOCALAPPDATA\ -recurse -force
if (!(test-path c:\folder\program)){return}
}
But that script quits if the COPYING.TXT exists. I think I need to create a function and insert that function within itself, or a nested while loop, but that is starting to make my head hurt.
Any help would be greatly appreciated. Thanks guys.
© Stack Overflow or respective owner