How to verify files exist... kinda...
Hello,
I'm trying to verify that each file in a list exist. I can successfully read the text file (which contains the list of files) into an array. (Each containing one filepath.) Each path has quotes around it and I have easily removed them. I then created an array and put the file path to every file (in the specified directory) into each dimension. My problem now is, I need a way to compare the two lists, verifying that each file that exists is in the other list.
So I suppose that I am not looking for a way to verify files exist but rather that each file that does exist is in my list. Understand?
I have considered multiple ways of doing this but they have either failed or I have found that they are not what I am looking for. Maybe there is a way to check if the specified string (or file path rather) exists in the specified array (which would contain the list of file paths that need to be verified).
... I hope this isn't too confusing...
I am using
Dim DIAs New DirectoryInfo("M:\TMDocs")
Dim FileList()As FileInfo = DI.GetFiles("*.pdf", SearchOption.AllDirectories)
to find all the files in the directory and subdirectories.
... Wouldn't that just check to see if a existing file exists?
FileList is a array containing the file paths of existing files. (Look in the code I supplied above.) I'm sorry I am very unclear but this is not the answer to my question.
I have two arrays. (FileList and UnverifiedFileList.) FileList contains the file paths of files that exist. UnverifiedFileList contains the file paths that an application (Time Matters) spits out. Time Matters is simply a database front-end each filepath in Time Matters is an 'entry' that is supposed to exist. Now, I have already wrote an app that makes sure that the entries in Time Matters are valid. I need an app that makes sure that every file in the specified directory has an entry in Time Matters.
I am exporting a list of entries from Time Matters and trying to compare it to exist files. But thank you very much for your support. Hopefully you understand me... (it's not easy).
So if I'm right on what your asking.
You have two arrays (FileList and UnverifiedFileList).
FileList Contains files that exists
UnverifiedFileList contains a list the application spits out.
Are you just trying to confirm that the entries in UnverifiedFileList exist in FileList ? In which case this really has nothing to do with files - its just verifying items exist in arrays.
Thank you very much, I believe this will do.
I do have one more minor question however, did you use a 'List(Of String)' because you needed the '.Contains' method? I just want to know so I can apply it to future apps. Thanks again!
Edit:
Sorry, spotty I didn't see your post until now. Well yes. This doesn't have anything to do with making sure files exist. If it did I'd simple put a File.Exists() in a For... Next loop. However I'd like to do the opposite.
Though, you said "Are you just trying to confirm that the entries in UnverifiedFileList exist in FileList ?", the answer to that is no. Other wya around. I want to confirm that the files in FileList exist in UnverifiedFileList. But thanks anyway.
2nd Edit:
Okay, the problem with using a list is that the method of reading the file paths (from Time Matters) into an array was File.ReadAllLines(). But, that will not work with a list...
Original code:
TimeMatters = File.ReadAllLines("File path of export file")
That will no longer work, do I need to use a loop to individually add file paths to the list? (I'm sorry I have very, very little knowledge of lists.... in fact I've never used one before but then again I've only been programming for 2 weeks.)
For the record, one of the the List(Of String) constructor overloads would allow you to pass in you source array from ReadAllLines, this would save you the hassel of populating it manually. Pseudo (don't have editor and intellisense handy) code:
Dim myList As List(Of String)
myList = New List(Of String)(ReadAllLines)