Question SOLVED: Copying files from /dirA to /dirC if not in /dirB

motoburn

Member
Joined
Jun 15, 2010
Messages
17
Location
Collinwood, TN
Programming Experience
Beginner
I have a strange and somewhat irritating situation.

I need to import data from files generated by a 3rd party program which scans our inventory as it passes through the production line.

This program, rather than inserting the data into a backend db or even a log file, creates a series of .asc files per item that passes.

I originally intended to watch that folder and move new additions to a temp location, import to our db, then move to a final resting place for archiving. As it turns out, i cannot move these files, because the program checks this directory to perform a few critical functions (
1. the file name serves as a primary key to ensure item ID's are not duplicated...
2. when running a sequential set, it auto-increments from the last file created.
)

Since I cannot move the files, is it possible through System.File.IO or some other means to copy files to a temp location, run my imports, then move to the final location then continue to watch this directory, and only move files to the temp location that do not yet exist in the final directory?

This whole thing seems absurd, but I need the data, and the writers of the program will not provide us with a real data file to query against, nor will they allow me the source files to write our own solution.

Any help or direction to a solution for this is MUCH appreciated.

Thank you,
Chris
p.s. sorry for the long abstract post.
 
Last edited:
Why do you need the intermediary? Just process all source files that is not in target directory, copy the source file to target directory before or after processing it. IO.Directory.GetFiles, if not targetFiles.Contains(sourceFile)...
 
Why do you need the intermediary?
wow, good point.

I have been searching for GetFiles stuff, and currently am using a loop to find and import these files with GetFiles.. so I guess I should put something like
If ... GetFiles(targetDir,foundfile) then

in my loop so I can proceed with the import, then copy it before the next foundfile.

wow... sounds so simple now. Thank you for the assist. :)
 
Update:

I originally had

VB.NET:
Dim dirLook As String = txtDefDir.Text

For Each foundBundle As String In My.Computer.FileSystem.GetFiles(dirLook, FileIO.SearchOption.SearchAllSubDirectories, "*.xls")

'do database stuff...
'do UI stuff (populate onscreen RichTexts and Listboxes showing user whats happening)
next

I now threw the following additions in there:
VB.NET:
Dim dirTarg As String = "C:\target\"

            If File.Exists(dirTarg & FileNameWithoutExtension(foundBundle) & ".xls") = False Then
'do loop
'do database and UI stuff
'do next loop

File.Copy(foundBundle,dirTarg & FileNameWithoutExtension(foundBundle) & ".xls")

end if

This may not be the cleanest bit of work, but I am now rolling where as the past couple of days I have been frustrated and stuck.

Thanks a ton JohnH ;)
 
Use Path.Combine and Path.ChangeExtension to manipulate your paths, rather than string concatenation with &
 
Back
Top