Results 1 to 6 of 6

Thread: Waiting for file, check filesize then process... Help please

  1. #1

    Thread Starter
    Addicted Member Chrispybee's Avatar
    Join Date
    Sep 2003
    Location
    North Wales, UK
    Posts
    217

    Waiting for file, check filesize then process... Help please

    I've written this little prog that will check for a file.
    If a file is found then will check the file size then pause, check the file size again and compaire the two. If the file size is same then process file else wait .

    If anyone can help, would be great.


    VB Code:
    1. Dim FSO As New FileSystemObject 'set fso as new file system object
    2.     Dim Filen As File               'This is a file
    3.     Dim FileLena, FileLenb As Long
    4. If File1.ListCount = 0 Then
    5.     FileName = File1.FileName
    6.    
    7. Do Until FileLena = FileLenb
    8.     Set Filen = FSO.GetFile(FileName)  'Set fullstring as full filename and pick the file
    9.     FileLena = Filen.Size           'Get file size
    10.     Text1.Text = Filen.Size         'display the filesize in text box 1
    11.     Wait 1                          'wait 1 seconds
    12.     FileLenb = Filen.Size           'Get file size
    13.     Text2.Text = Filen.Size         'display the filesize in text box 2
    14.     Wait 1
    15. Loop

  2. #2
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    In Front of my computer...
    Posts
    367
    I dont get it what is your question here ?
    Born to help others
    (If I've been helpful then please rate my post. Thanks)

    call me EJ or be slapped!

  3. #3

    Thread Starter
    Addicted Member Chrispybee's Avatar
    Join Date
    Sep 2003
    Location
    North Wales, UK
    Posts
    217
    I'm trying to check the size of a file, if filesize is the same then carry on else wait 1.

    When I run this, it dosn't seem to work... just waits and skips.

    Does this help??

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Waiting for file, check filesize then process... Help please

    I don't use FSO myself, it adds too much overhead for simple tasks like this.

    The FileLen function is easily enough in this case:
    VB Code:
    1. Dim FileLena [b]as Long[/b], FileLenb As Long  'FileLena was a variant as you did it ;)
    2. [b]If File1.ListCount = 0 Then  'erm... this seems like a problem![/b]
    3.     FileName = File1.FileName
    4.    
    5. Do
    6.     FileLena = FileLen(FileName)           'Get file size
    7.     Text1.Text = FileLena         'display the filesize in text box 1
    8.     Wait 1                          'wait 1 seconds
    9.     FileLenb = FileLen(FileName)           'Get file size
    10.     Text2.Text = FileLenb         'display the filesize in text box 2
    11.     Wait 1
    12. Loop [b]Until FileLena = FileLenb [/b] 'you want the code to run at least once, so this needs to go at the end

  5. #5
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    Add this to a timer event I think it should work
    VB Code:
    1. Private Function FileSizeChanged(ByVal filename As String) As Boolean
    2.     Dim RetVal As Boolean
    3.     Static lngSize As Long
    4.     If lngSize <> FileLen(filename) Then
    5.         RetVal = True
    6.     Else
    7.         RetVal = False
    8.     End If
    9.     FileSizeChanged = RetVal
    10. End Function

  6. #6

    Thread Starter
    Addicted Member Chrispybee's Avatar
    Join Date
    Sep 2003
    Location
    North Wales, UK
    Posts
    217
    I've been trying this for sometime and working great. But when I get a large file that gets copied over the network, it fails.

    It tries to use the file before the 'true' file size is the same.

    I could get my program to wait a number of seconds but my only fear is that one day it will try and process a file that's still being copied.

    Any one got any ideas?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width