Beispiel #1
0
 public static MyFile ListDrive(string drive)
 {
     DirectoryInfo di = new DirectoryInfo(@drive);
     MyFile root = new MyFile(Iterator, drive, 1, -1);
     SqlCommand myCommand = new SqlCommand("INSERT INTO table (id, name,is_directory,parent) " +
                              "Values (" + Iterator + "," + drive + ",1,-1)", conn);
     myCommand.ExecuteNonQuery();
     ListDriveRec(di, Iterator++);
     return root;
 }
Beispiel #2
0
        public static MyFile ListDrive(string drive)
        {
            DirectoryInfo di        = new DirectoryInfo(@drive);
            MyFile        root      = new MyFile(Iterator, drive, 1, -1);
            SqlCommand    myCommand = new SqlCommand("INSERT INTO table (id, name,is_directory,parent) " +
                                                     "Values (" + Iterator + "," + drive + ",1,-1)", conn);

            myCommand.ExecuteNonQuery();
            ListDriveRec(di, Iterator++);
            return(root);
        }
Beispiel #3
0
        public static void ListDriveRec(DirectoryInfo dir, int parent)
        {
            // Subdirs
            try         // Avoid errors such as "Access Denied"
            {
                foreach (DirectoryInfo iInfo in dir.GetDirectories())
                {
                    MyFile file = new MyFile(Iterator++, iInfo.Name, 1, parent);
                    SqlCommand myCommand = new SqlCommand("INSERT INTO table (id, name,is_directory,parent) " +
                                     "Values (" + Iterator + "," + iInfo.Name + ",1,"+parent+ ")", conn);
                    myCommand.ExecuteNonQuery();
                    ListDriveRec(iInfo, Iterator);
                }
            }
            catch (Exception e)
            {
                LogWriter.WriteLine(e.ToString());
            }

            // Subfiles
            try         // Avoid errors such as "Access Denied"
            {
                foreach (FileInfo iInfo in dir.GetFiles())
                {
                    MyFile file = new MyFile(Iterator++, iInfo.Name, 0, parent);
                    SqlCommand myCommand = new SqlCommand("INSERT INTO table (id, name,is_directory,parent) " +
                                     "Values (" + Iterator + "," + iInfo.Name + ",0," + parent + ")", conn);
                    myCommand.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                LogWriter.WriteLine(e.ToString());
            }
        }