Saved Bookmarks
| 1. |
Solve : Watch Folder - Need Batch file? |
|
Answer» Hi All, Hi All,So... @echo off :loop if exist FILENAME goto cont ping localhost -N 10 -w 1000 > nul goto loop :cont move FILENAME BACKUPFOLDER rest of commands hereQuote from: mrgreekgod on May 11, 2009, 12:26:26 PM I need a batch file which watches the folder for a particular file[i have 30 to 40 files,any one of them can be placed] for every 10 secs,if found move the file to backup folder,delete the same and trigger the vbs file to do some action. you can do the whole thing in vbscript: Code: [Select]watch="." dest=".\backup\" set d=createobject("scripting.dictionary") with createobject("scripting.filesystemobject") if not .folderexists(dest) then .createfolder dest do wsh.echo "tick count, checking.." for each f in .getfolder(watch).files if not d.exists(f.name) then wsh.echo "adding to watch list:",f.name d.add f.name, f.datelastmodified elseif f.datelastmodified<>d.item(f.name) then wsh.echo f.name,"was modified, move to",dest,"folder" f.move dest end if next wsh.sleep 10000 loop end with Quote from: mrgreekgod on May 11, 2009, 12:26:26 PM [i have 30 to 40 files,any one of them can be placed] for every 10 secs,not sure about "any one of them can be placed", but the above code will watch current folder for modified file, if modified move the file to backup folder.Quote from: Helpmeh on May 11, 2009, 02:39:18 PM So... If you want the script to sleep for 10 secs, you may need 11 requests in the "ping" COMMAND. Because, in the ICMP protocal, the first response takes no time nearly. Code: [Select]ping localhost -n 11 -w 1000 > nulQuote from: Batcher on May 11, 2009, 11:53:14 PM If you want the script to sleep for 10 secs, you may need 11 requests in the "ping" command. Because, in the ICMP protocal, the first response takes no time nearly.the -w 1000 will make it wait 1000 miliseconds for each ping, so -n 10 -w 1000 WOULD be 10 seconds. -n 11 would be 11 seconds. |
|