Clicky

i need code in c# to search for file in flash drive

for example :
flash drive : "G"
then  i need to search if file " test.txt " exist in  flash drive (" G " )  or not , if exist get the path

that's it
thanks

asked 11/23/2011 05:35

YUYU's gravatar image

YUYU ♦♦


1 Answers:
From the help files:

using System;
using System.IO;

class Test
{
    public static void Main()
    {
        try
        {
            DirectoryInfo di = new DirectoryInfo(@"c:\");

            // Get only subdirectories that contain the letter "p."
            DirectoryInfo[] dirs = di.GetDirectories("*p*");

            Console.WriteLine("Number of directories with a p: {0}", dirs.Length);

            // Count all the files in each subdirectory that contain the letter "e."
            foreach (DirectoryInfo diNext in dirs)
            {
                Console.WriteLine("The number of files in {0} with an e is {1}", diNext,
                    diNext.GetFiles("*e*").Length);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("The process failed: {0}", e.ToString());
        }
    }
}

Just modify the code as you need it.
link

answered

AndyAinscow's gravatar image

AndyAinscow

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×1

Asked: 11/23/2011 05:35

Seen: 237 times

Last updated: 12/09/2011 03:29