By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,689 Members | 1,490 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,689 IT Pros & Developers. It's quick & easy.

File locking problem

P: n/a
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.
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Look into the FileSystemWatcher instead of the timer. It is made to fix
problems like this.

"Aaron Smith" <th**********@smithcentral.net> wrote in message
news:Mz******************@newssvr19.news.prodigy.c om...
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.

Nov 21 '05 #2

P: n/a
Ok, thanks.. I will look into that..

Aaron

Ray Cassick (Home) wrote:
Look into the FileSystemWatcher instead of the timer. It is made to fix
problems like this.

"Aaron Smith" <th**********@smithcentral.net> wrote in message
news:Mz******************@newssvr19.news.prodigy.c om...
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.
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.