Windows Develop Bookmark and Share   
 index > Windows Forms General > C# + Replace
 

C# + Replace

hello,

how can replase fullname to name



private void button1_Click(object sender, EventArgs e)
        {
    
            foreach (string match in Search(path, "*.exe"))
            {
                Console.WriteLine(match.);  < ------------------------- Replace
                Counter++;
            }
            Console.WriteLine("================================");
            Console.WriteLine("Done :"+Counter);
        }


 static IEnumerable<string> Search(string root, string searchPattern)
        {
        Queue<string> dirs = new Queue<string>();
        dirs.Enqueue(root);
        while (dirs.Count > 0) {
            string dir = dirs.Dequeue();

            // files
            string[] paths = null;
            try {
                paths = Directory.GetFiles(dir, searchPattern);

            } catch { } // swallow

            if (paths != null && paths.Length > 0) {
                foreach (string file in paths) {
                    yield return file;
                }
            }

            // sub-directories
            paths = null;
            try {
                paths = Directory.GetDirectories(dir);
            } catch { } // swallow

            if (paths != null && paths.Length > 0) {
                foreach (string subDir in paths) {
                    dirs.Enqueue(subDir);
                }
            }
        }
        }



output
=======
C:\Users\MeUser\Documents\Mijn Files\MySmartUSB drivers\cp210x Driver\CP210xVCPInstaller.exe
C:\Users\MeUser\Documents\Mijn Files\NI Electronics\NI LabVIEW 8.5\autorun.exe
C:\Users\MeUser\Documents\Mijn Files\NI Electronics\NI LabVIEW 8.5\setup.exe
C:\Users\MeUser\Documents\Mijn Files\NI Electronics\NI Multisim 10.1\autorun.exe
C:\Users\MeUser\Documents\Mijn Files\NI Electronics\NI Multisim 10.1\setup.exe
=======


and I like to have

output
=======
CP210xVCPInstaller.exe
autorun.exe
setup.exe
autorun.exe
setup.exe
=======








Power-Mosfet  Sunday, September 20, 2009 1:16 PM
the name member of the fileinfo class should do what you want.

WM_HOPETHISHELPS
-thomas woelfer
http://www.die.de/blog
  • Marked As Answer byPower-Mosfet Sunday, September 20, 2009 2:17 PM
  •  
thomas_woelfer  Sunday, September 20, 2009 1:51 PM
the name member of the fileinfo class should do what you want.

WM_HOPETHISHELPS
-thomas woelfer
http://www.die.de/blog
  • Marked As Answer byPower-Mosfet Sunday, September 20, 2009 2:17 PM
  •  
thomas_woelfer  Sunday, September 20, 2009 1:51 PM
Use System.IO.Path.GetFileName("File Path")


In your code

foreach (string match in Search(path, "*.exe"))
{
Console.WriteLine(System.IO.Path.GetFileName(match)); < ------------------------- Replace
Counter++;
}

Gaurav Khanna
Khanna Gaurav  Sunday, September 20, 2009 2:52 PM
hi,

yes I know thank you.
Power-Mosfet  Sunday, September 20, 2009 2:55 PM

You can use google to search for other answers

Custom Search

More Threads

• Printing MDI Child Form
• My wish list
• Strech image in ImageList of button
• Opening existing Forms?
• Control Position change when resolution changes.
• VC++ variables in labels
• Focus grid next cell when Enter key press
• VScrollBar in a Panel Problem
• Printing help needed ?
• Programmatically sending e-mail