Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Determining When a File Is Ready
#1
When I copy files from another computer on the local LAN, the source file may still be being copied or downloaded (the file size is changing).

The method in the code below may be too simplistic.

Is there a more accurate way to determine whether the file is ready?

I have seen similar code in a macro on a forum, but after trying many keywords, I still haven't found it.

Function Function6
Code:
Copy      Help
str destFolder="$desktop$\T"
mkdir destFolder

sub.netCopy("\\PC001\d\S" destFolder)

#sub netCopy
function ~srcFolder ~dstFolder
,;; Get full path list of .avi and .mp4 files
,ARRAY(str) a
,GetFilesInFolder a srcFolder "*.avi[]*.mp4"
,
,int i
,for i 0 a.len
,,str filePath = a[i]
,,
,,;; Wait for file size to stabilize (max 60 seconds)
,,int prevSize = -1
,,int curSize
,,int waited = 0
,,rep
,,,Dir d.dir(filePath)
,,,curSize = d.FileSize
,,,if(prevSize != -1 and curSize = prevSize) break
,,,prevSize = curSize
,,,waited + 2
,,,if(waited >= 60) break
,,,2   ;; wait 2 seconds
,,
,,;; Copy file (replace if target exists)
,,cop- filePath dstFolder
#2
Found in Archive.

Function WaitForFileReady
Code:
Copy      Help
;/
function $_file [^waitmax]

;Waits until file exists, is not empty, and is not locked.

;waitmax - max number of seconds to wait. 0 is infinite.


if(waitmax<0 or waitmax>2000000) end ES_BADARG
opt waitmsg -1
int wt(waitmax*1000) t1(GetTickCount)

Dir d
rep
,if d.dir(_file) and d.FileSize
,,__HFile f.Create(_file OPEN_EXISTING); err
,,if(f) f.Close; break
,
,if(wt>0 and GetTickCount-t1>=wt) end "wait timeout"
,0.1

;info: the d.FileSize is for apps that at first create empty file, close it, then later open again and write.
#3
thank you so much!


Forum Jump:


Users browsing this thread: 1 Guest(s)