I have a folder which is currently filled with files from another software. AHK watches the folder and starts a FileMove if it finds files.
Of course it could happen that a file is still "under construction" (still copying from other software) and AHK starts to "FileMove". What will happen?
- an errorlevel and a skipped file?
- an errorlevel and a fragmented / destroyed source/target?
- an internal "retry until success"?
Thanks and regards
"FileMove" a file which is currently created
"FileMove" a file which is currently created
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: "FileMove" a file which is currently created
most likely 2 but 1 can also happen
Re: "FileMove" a file which is currently created
TLM wrote:most likely 2 but 1 can also happen
Thanks for your info.
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: "FileMove" a file which is currently created
There are often ways of determining when a file has been copied or saved by a source application.
The most common is a status bar/control message, others may be some kind of single blocking action like disabling the ability to copy more files while one is being processed or even the change of style codes on main windows or controls after a file is complete.
Perhaps you could find some indicator in the source app ? Just a thought
The most common is a status bar/control message, others may be some kind of single blocking action like disabling the ability to copy more files while one is being processed or even the change of style codes on main windows or controls after a file is complete.
Perhaps you could find some indicator in the source app ? Just a thought
Re: "FileMove" a file which is currently created
Wrote a little example to see if the file size has changed in the last two seconds. If the filesize it the same; it's probably done being created. Increase the time if it builds slower than that.
Code: Select all
FileGetSize, OutputVar1 , %FilePath_File%, k
Sleep 2000
FileGetSize, OutputVar2 , %FilePath_File%, k
If (OutputVar1 = OutputVar2) {
;File hasn't changed size in 2 seconds, must be done being constructed
FileMove, %FilePath_File%, %DestPattern%
}
Re: "FileMove" a file which is currently created
Hi
thanks both for your postings. I think that both solutions can not be used for my problem, because
a) I have no connection to the source app; I'm only the receiver of the files at the end of the network-pipe.
b) Sleeping could work, but with some 1000s of files per day the delay would be unacceptable.
Also the way "copy source to temp - compare source with temp - if source is equal to temp then source is OK - move source to target and delete temp" has to prove its usability ...
thanks both for your postings. I think that both solutions can not be used for my problem, because
a) I have no connection to the source app; I'm only the receiver of the files at the end of the network-pipe.
b) Sleeping could work, but with some 1000s of files per day the delay would be unacceptable.
Also the way "copy source to temp - compare source with temp - if source is equal to temp then source is OK - move source to target and delete temp" has to prove its usability ...
Peter (AHK Beginner) / Win 10 x64, AHK Version v1.1.33
Re: "FileMove" a file which is currently created
Didn't know this was being applied to 1000's of files.
Would recommend one of two things.
1) Use an array to keep track of each file and its size,size_check2,current_location,destination,time
2) Use Robocopy to handle all of your file moving; fairly confident it will not interact with a file that is still being written. Check the options and do some tests.
If it takes multiple days; there is an option to only move/copy the file after x days.
If you know how to use arrays or can learn; here's part of my production tool that monitors filesizes; I threw a filemove in there for your use. I only monitor 4 files but there would be no problem filling the array with 1000+ files to handle.
Would recommend one of two things.
1) Use an array to keep track of each file and its size,size_check2,current_location,destination,time
2) Use Robocopy to handle all of your file moving; fairly confident it will not interact with a file that is still being written. Check the options and do some tests.
If it takes multiple days; there is an option to only move/copy the file after x days.
If you know how to use arrays or can learn; here's part of my production tool that monitors filesizes; I threw a filemove in there for your use. I only monitor 4 files but there would be no problem filling the array with 1000+ files to handle.
Code: Select all
Loop % AllFiles_Array.MaxIndex() {
FilePath_File := AllFiles_Array[A_Index,"FileLocation"]
;Get Modified Time and assign it to the Array
AllFiles_Array[A_Index,"ModifiedTime"] := Fn_DataFileInfoTime(FilePath_File)
;Get File Size and assign it to the Array
AllFiles_Array[A_Index,"Size"] := Fn_DataFileInfoSize(FilePath_File)
;If the Filesize is the same as last time it was checked
If (AllFiles_Array[A_Index,"LastCheck"] = AllFiles_Array[A_Index,"Size"]) {
;Then increment the Counter for not growing
AllFiles_Array[A_Index,"NotGrowingCounter"] += 1
FileMove, %FilePath_File%, %DestPattern%
} Else {
;Do nothing
}
AllFiles_Array[A_Index,"LastCheck"] := AllFiles_Array[A_Index,"Size"]
}
;~~~Functions~~~
Fn_DataFileInfoSize(para_File)
{
l_FileSize := ;MakeThis Variable Empty
;Check the size of the file specified in the Function argument/option
FileGetSize, l_FileSize, %para_File%, k
;If the filesize is NOT blank
If (l_FileSize != "")
{
;Exit the Function with the value of the filesize
Return %l_FileSize%
}
;filesize was blank or not understood. Return the word "ERROR"
Return "ERROR"
}
Re: "FileMove" a file which is currently created
If you just check when the file was last modified using FileGetTime and only move files that haven't been modified in the last few minutes (or whatever length of time is appropriate), then there is no need for your script to sleep or anything.
Re: "FileMove" a file which is currently created
uh that's a simpler way to do it; yes ^^"
Who is online
Users browsing this forum: Google [Bot], Spawnova, william_ahk and 259 guests