Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
how to check if the give array file names exist in the local directory..In others multiple flies name needs to be checked if they exist in the directory.....Any sample codes would be of great help..

Thanks

while (myReader.Read())
            {
                string  i = myReader["Ref_Link"].ToString();
                test.Add(i);
                String[] filenames = (String[])test.ToArray(typeof(string));
}

This String[] filenames contains the list of file names.
Posted
Updated 26-Jul-12 17:33pm
v2
Comments
[no name] 26-Jul-12 22:31pm    
Have you tried if (filenames.Contains(yourfilename)) ?
Sergey Alexandrovich Kryukov 26-Jul-12 23:15pm    
Not clear: does the array filenames contain full path names or file names without directory? In either case, what's the problem?
--SA

Please use System.IO.File.Exist:
http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx[^].

(Please see my comment to the question. You either pass each file name to this method, or combine it with the full path name of the directory in question.)

—SA
 
Share this answer
 
Comments
Abhinav S 26-Jul-12 23:33pm    
Correct. 5.
Sergey Alexandrovich Kryukov 26-Jul-12 23:34pm    
Thank you, Abhinav.
--SA
Here are a couple of links that provide solutions -

http://codingcluster.blogspot.in/2011/10/check-if-file-exists-using-c.html[^]
http://www.dotnetperls.com/file-exists[^]


You can in addition, try exploring FileInfo.Exists()[^] as well.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 27-Jul-12 0:56am    
Same thing; we probably were writing at the same time; a 5.
--SA
Abhinav S 27-Jul-12 1:23am    
Thanks SA. Note that I've mentioned FileInfo.Exists as well. :)
Sergey Alexandrovich Kryukov 27-Jul-12 16:41pm    
Noted. Well, not exactly the same things. :-)
Cheers,
--SA
Here is a very short sample:
C#
private void button1_Click(object sender, EventArgs e)
{
   string[] filenames = new string[4];
   filenames[0] = "test.txt";
   filenames[1] = "test.txt";
   filenames[2] = "test2.txt";
   filenames[3] = "test3.txt";
   string strPath = @"C:\Temp\";
   foreach(string str in filenames)
   {
      if (!File.Exists(strPath + str))
         MessageBox.Show("File: " + str + " does not exist in folder: " + strPath);
   }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900