Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
string[] drives = Directory.GetLogicalDrives();
            foreach (string str in drives)
            {
                int i = 0;
                string[] driv = Directory.GetDirectories(str);
              string s1 = str + "WINDOWS";//C:\Documents and Settings  WINDOWS
              //  string s1 = str + "XMLFile1.xml";
                foreach (string str1 in driv)
                {
                    if (str1.ToLower() == s1.ToLower())
                    {



here my problem is when the drive is readonly(cd rom or dvd rom) that the exception will raising i want avoid that drives how can i do it please help me
Posted

1 solution

you could use try/catch around the Directory.GetDirectories call. It looks like you are trying to get the windows folder which can be done in a much neater way like this:
string windowsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
 
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