473,385 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

File locking problem

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
2 2816
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Dino | last post by:
dear all, i've created an application for a customer where the customer can upload ..csv-files into a specified ftp-directory. on the server, a php-script, triggered by a cronjob, reads all the...
0
by: Andrew Dowding | last post by:
Hi Everybody, I have been looking at problems with my Windows Forms C# application and it's little Jet 4 (Access) database for the last few days. The Windows Forms app implements a facade and...
7
by: emanshu | last post by:
HI all, I an designing an application in C++. i want to open file requested by end user but i want to reflect an error to user if file is already opened by some other application.. will anybody...
4
by: darrel | last post by:
I've been dealing with a file locking issue for a while. Our CMS spits out a new XML file each time an item in the DB is updated. This XML file is basically our site menu, and is what we use on...
1
by: ABCL | last post by:
Hi All, I am working on the situation where 2 different Process/Application(.net) tries to open file at the same time....Or one process is updating the file and another process tries to access...
13
by: George | last post by:
Hi, I am re-writing part of my application using C#. This application starts another process which execute a "legacy" program. This legacy program writes to a log file and before it ends, it...
3
by: dchadha | last post by:
Hi, I am working on application in C# which uses and stores data in xml file. This app can use xml file from two different ways: (a) From User Interface (Windows application) and (b) From...
17
by: shineofleo | last post by:
Here is the situation: I wrote a VB programm, which stores all the information in a single Access database file using jet engine. It worked well, however one of my customs reported that there was...
17
by: Peter Duniho | last post by:
I searched using Google, on the web and in the newsgroups, and found nothing on this topic. Hopefully that means I just don't understand what I'm supposed to be doing here. :) The problem: ...
7
by: =?Utf-8?B?UGFycm90?= | last post by:
I am receiving a "file is being used by another process" error message whenever I try to access a text file that I had previously created and then closed. This only happens when I test in a...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.