rutledgj
asked on
Weird problem reading files in directory
I have an application that reads in .doc files from a directory, processes them and moves them to an archive directory. My problem is that occassionally the application will leave a couple of files. It is like it just doesn't even see them. I'm using this code to get a list of all the files:
files = Directory.GetFiles(sourceP ath, "*.doc")
For Each f As String In files ...
If I go into the dir and open the files and close them, the app picks them up. The files get ftp'd to the directory. Most files get processed but there is always a couple not processed.
Any ideas what might cause this or how to fix it?
files = Directory.GetFiles(sourceP
For Each f As String In files ...
If I go into the dir and open the files and close them, the app picks them up. The files get ftp'd to the directory. Most files get processed but there is always a couple not processed.
Any ideas what might cause this or how to fix it?
ASKER
Regardless, according to the MSDN documentation it should pick up both, but to answer your question, I can see the files and they are indeed .doc files.
They application opens the word doc using the Aspose component and saves it as a .txt file. Then it moves the .doc file to the archive folder. I have checked and the files do not already exist in archive. The remaining code operates only on the .txt file so it is irrelevant.
They application opens the word doc using the Aspose component and saves it as a .txt file. Then it moves the .doc file to the archive folder. I have checked and the files do not already exist in archive. The remaining code operates only on the .txt file so it is irrelevant.
'look for .doc files
'loop through the files and convert to txt file.
files = Directory.GetFiles(sourcePath, "*.doc")
For Each f As String In files
fileName = Path.GetFileNameWithoutExtension(f)
Try
Dim aw = New Aspose.Words.Document(f)
'save word document as txt file
aw.Save(sourcePath & "\" & fileName & ".txt", SaveFormat.Text)
aw = Nothing
'Move .doc file to archive folder
File.Move(sourcePath & "\" & tmpF, MyProfile.ArchiveFilePath & "\" & tmpF)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The process fails on the files = Directory.GetFiles(sourceP ath, "*.doc") code. It just doesn't return them into the files variable.
Is the "sourcePath" a local folder or a unc path?
have you tried the snippet i sent? its a cleaner way to use and access files and folders
it may also throw an error that may shed a little more light on the issue
have you tried the snippet i sent? its a cleaner way to use and access files and folders
it may also throw an error that may shed a little more light on the issue
ASKER
It is a unc path. I'll give the code a try but since I can't predict when the problem will occur (it doesn't happen each time) I'm not sure when I can tell that it helped.
If its a unc path then there is a few reasons why it could be failing
Is it a DFS share or just a shared folder? is the source machine on the local network?
I know i ask a lot of questions but seeing the full picture allows you to pick out the details better
Is it a DFS share or just a shared folder? is the source machine on the local network?
I know i ask a lot of questions but seeing the full picture allows you to pick out the details better
ASKER
The paths look like this: \\FSSAN\EDIFiles\Lab\CNC-L yons\newda ta
I guess it is a DFS Share but not sure (how do I tell?). It is on the company network
I guess it is a DFS Share but not sure (how do I tell?). It is on the company network
if you right click on the share root " \\FSSAN\EDI" and call the properties it should have a tab named "DFS", if it hasnt then its probably not
DFS shares generally only cause problems if one of the servers that host the DFS are offline, they will be listed on the DFS tab
it looks like connectivity is the problem,
If it was me i would add a textfile to the folder and rename it "dummy.dat"
then when your process runs try to read that file first as you know it should be there!
if it isnt then either try again later or add code to handle the error
DFS shares generally only cause problems if one of the servers that host the DFS are offline, they will be listed on the DFS tab
it looks like connectivity is the problem,
If it was me i would add a textfile to the folder and rename it "dummy.dat"
then when your process runs try to read that file first as you know it should be there!
if it isnt then either try again later or add code to handle the error
ASKER
THere is no DFS tab. I don't think connectivity is the issue. It will pick up other documents in the folder without problem. I had 2 files unprocessed this morning. I ran the application and it didn't pick them up. I then opened the files with Word and closed them and reran the application and it processed them.
Where are the documents coming from?
With you saying that you opened and closed the files i'm wondering if the lock file could be causing the problem
on your loop do you have any code in the catch portion of the try statement?
it may be worth adding something to write any captured error to a text file
With you saying that you opened and closed the files i'm wondering if the lock file could be causing the problem
on your loop do you have any code in the catch portion of the try statement?
it may be worth adding something to write any captured error to a text file
ASKER
Actually in that catch I didn't have any code. Had plenty in the inner try catch codes. I'll add something there and see what happens. (There is a try before the files = Directory.GetFiles(sourceP ath, "*.doc") code.). I'll also try your code snippet. Thanks.
Happy to Help :)
Can you post a larger portion of code?