Home All Groups Group Topic Archive Search About
Author
1 Apr 2005 12:58 PM
Aaron Smith
I have a small application that runs in the taskbar. All it has is a
timer that goes off every second. It looks at a list of files on a
source and then on a destination folder. If it can't find a file in the
source folder in the destination folder, it copies it into the
destination. Everything is working fine, except for one thing... There
is another application that creates the files in the source folder.
This application creates a file in the source folder, then it fills the
file with data...

The application that creates the file locks up until the copy
application is closed.. I've tried setting the timer to every 30
seconds, but it still locks up.

Is there a way to check to see if a file is in use first and then just
skip that file?

Here is some code that I use:

         SourceFiles = System.IO.Directory.GetFiles(txtSource.Text)
         DestFiles = System.IO.Directory.GetFiles(txtDestination.Text)
         Dim iCount As Integer
         For iCount = 0 To SourceFiles.Length - 1
             bFound = False
             Dim iCountDest As Integer
             For iCountDest = 0 To DestFiles.Length - 1
                 If System.IO.Path.GetFileName(DestFiles(iCountDest)) =
System.IO.Path.GetFileName(SourceFiles(iCount)) Then bFound = True
             Next
             If bFound = False Then
                 sourcePath = SourceFiles(iCount)
                 destPath = txtDestination.Text & "\" &
System.IO.Path.GetFileName(SourceFiles(iCount))

                 System.IO.File.Copy(sourcePath, destPath)
             End If
         Next

Thanks,
Aaron
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.

Author
1 Apr 2005 1:24 PM
Ray Cassick (Home)
Look into the FileSystemWatcher instead of the timer. It is made to fix
problems like this.

Show quoteHide quote
"Aaron Smith" <thespirit***@smithcentral.net> wrote in message
news:Mzb3e.13379$ZB6.7510@newssvr19.news.prodigy.com...
>I have a small application that runs in the taskbar. All it has is a
> timer that goes off every second. It looks at a list of files on a
> source and then on a destination folder. If it can't find a file in the
> source folder in the destination folder, it copies it into the
> destination. Everything is working fine, except for one thing... There
> is another application that creates the files in the source folder.
> This application creates a file in the source folder, then it fills the
> file with data...
>
> The application that creates the file locks up until the copy
> application is closed.. I've tried setting the timer to every 30
> seconds, but it still locks up.
>
> Is there a way to check to see if a file is in use first and then just
> skip that file?
>
> Here is some code that I use:
>
>         SourceFiles = System.IO.Directory.GetFiles(txtSource.Text)
>         DestFiles = System.IO.Directory.GetFiles(txtDestination.Text)
>         Dim iCount As Integer
>         For iCount = 0 To SourceFiles.Length - 1
>             bFound = False
>             Dim iCountDest As Integer
>             For iCountDest = 0 To DestFiles.Length - 1
>                 If System.IO.Path.GetFileName(DestFiles(iCountDest)) =
> System.IO.Path.GetFileName(SourceFiles(iCount)) Then bFound = True
>             Next
>             If bFound = False Then
>                 sourcePath = SourceFiles(iCount)
>                 destPath = txtDestination.Text & "\" &
> System.IO.Path.GetFileName(SourceFiles(iCount))
>
>                 System.IO.File.Copy(sourcePath, destPath)
>             End If
>         Next
>
> Thanks,
> Aaron
> --
> ---
> Aaron Smith
> Remove -1- to E-Mail me. Spam Sucks.
Author
1 Apr 2005 1:54 PM
Aaron Smith
Ok, thanks.. I will look into that..

Aaron

Ray Cassick (Home) wrote:
Show quoteHide quote
> Look into the FileSystemWatcher instead of the timer. It is made to fix
> problems like this.
>
> "Aaron Smith" <thespirit***@smithcentral.net> wrote in message
> news:Mzb3e.13379$ZB6.7510@newssvr19.news.prodigy.com...
>
>>I have a small application that runs in the taskbar. All it has is a
>>timer that goes off every second. It looks at a list of files on a
>>source and then on a destination folder. If it can't find a file in the
>>source folder in the destination folder, it copies it into the
>>destination. Everything is working fine, except for one thing... There
>>is another application that creates the files in the source folder.
>>This application creates a file in the source folder, then it fills the
>>file with data...
>>
>>The application that creates the file locks up until the copy
>>application is closed.. I've tried setting the timer to every 30
>>seconds, but it still locks up.
>>
>>Is there a way to check to see if a file is in use first and then just
>>skip that file?
>>
>>Here is some code that I use:
>>
>>        SourceFiles = System.IO.Directory.GetFiles(txtSource.Text)
>>        DestFiles = System.IO.Directory.GetFiles(txtDestination.Text)
>>        Dim iCount As Integer
>>        For iCount = 0 To SourceFiles.Length - 1
>>            bFound = False
>>            Dim iCountDest As Integer
>>            For iCountDest = 0 To DestFiles.Length - 1
>>                If System.IO.Path.GetFileName(DestFiles(iCountDest)) =
>>System.IO.Path.GetFileName(SourceFiles(iCount)) Then bFound = True
>>            Next
>>            If bFound = False Then
>>                sourcePath = SourceFiles(iCount)
>>                destPath = txtDestination.Text & "\" &
>>System.IO.Path.GetFileName(SourceFiles(iCount))
>>
>>                System.IO.File.Copy(sourcePath, destPath)
>>            End If
>>        Next
>>
>>Thanks,
>>Aaron
>>--
>>---
>>Aaron Smith
>>Remove -1- to E-Mail me. Spam Sucks.
>
>
>


--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.