smitha
smitha

Reputation: 13

How to find a missing file from a directory

I have a directory in which 'wav' files are stored. These files's names are sequential in order ie 1.wav, 2.wav, 3.wav.... etc.

I have to find out the missing wav file, like if 3.wav is missing then I have to find out that and the name '3' should given to a variable.

How can I do this?

Upvotes: 0

Views: 416

Answers (1)

Darren
Darren

Reputation: 70806

You could use a simple loop and assign the variable to the loop counter and use File.Exists:

List<yourType> missingFiles = new List<yourType>();
string path;

for (var i = 0; i<length; i++) {
   path = "path\" + i + ".wav";
   if (!File.Exists(path) {
       missingFiles.Add(path);
   }
}

http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx

Upvotes: 1

Related Questions