Question List Files without matching .pdf (abc123.doc and abc123.pdf) in same directory

GoodJuJu

Member
Joined
Apr 26, 2010
Messages
24
Location
England
Programming Experience
5-10
Hi, I wonder if somebody could point me in the right direction.

I have an 'In' folder that users drop all different types of files into (.doc, .xls, .rtf, .pdf etc.).
Each file that gets dropped into the 'In' folder should have a matching .pdf file (i.e. abc123.doc and abc123.pdf)

I have a program which looks into this 'In' directory at regular intervals and moves filename.* to another directory. The folder the files get moved to depends on the first 2 characters of the filename (12-abc.doc might get copied to folder '12' etc).

All the files placed in the 'In' folder should have both a native file and a matching .pdf i.e. (abc123.doc and abc123.pdf)
In some cases the native file is missing. In some cases the .pdf is missing.

There are 2 things that I want to do.

1.) I want to prevent files being moved from the 'In' folder if a .pdf does not exist (I think I can deal with this one ok).
I think perhaps a For Next Loop Array for filenames minus the file extension and if it already exists in the array then copy them (but what if someone has got a .doc and a .xls but no .pdf?!?!? I'm sure somebody could tell me a simple way of achieving this.

2.) This is the part I am struggling with. I need to look in existing folders that files have already been copied to and list:

a.) Native file without matching .pdf
b.) .pdf without matching native file
c.) .pdf with matching native file

I consider myself a reasonable programmer, but this is stumping me right now.

Any help anybody can offer is much appreciated - Thanks.
 
My code would be something like :-

VB.NET:
Dim NativeList as new List (of String)
Dim PDFList as new List (of String)

Obtain the list of all files, and if the extension is NOT PDF, and the filename (without extension) is not already in the NativeList, then add it (without extension) to the Native List.

Obtain a list of all PDF files, and add them to the PDFList (without extension).

Your solutions then become :-

a.) Native file without matching .pdf

VB.NET:
For Each NativeFile as string in NativeList
    If PDFList.Contains (NativeFile) = FALSE THEN
        'PDF file missing
    EndIf
Next

b.) .pdf without matching native file

VB.NET:
For Each PDFFile as string in PDFList
    If NativeList.Contains (PDFFile) = FALSE THEN
        'Native file missing
    EndIf
Next

c.) .pdf with matching native file

VB.NET:
For Each PDFFile as string in PDFList
    If NativeList.Contains (PDFFile) = TRUE THEN
        'Native file exists
    EndIf
Next

Please note - this has not been tested, and has been hand written :)
 
InertiaM, many thanks for your help - much appreciated!! Sorry for the delay in replying... Royal Weddings, Bank Holidays and the like I'm afraid!
 
Back
Top