private void CleanUpFolder(System.IO.DirectoryInfo dir)
        {

            System.IO.FileInfo [] fis = dir.GetFiles("ASCOM." + SharedResources.TELESCOPE_DRIVER_NAME + "*.*");
            foreach (System.IO.FileInfo fi in fis)
            {
                try
                {
                    if (DateTime.Now  - fi.LastWriteTime > TimeSpan.FromDays(SharedResources.DAYS_TO_KEEP_LOGS))
                    {
                        fi.Delete();
                    }
                }
                catch { }
            }

            // remove the folder if there are no files left:
            fis = dir.GetFiles();
            if (fis == null || fis.Length == 0)
            {
                try
                {
                    dir.Delete();
                }
                catch { }
            }
        }
        /// <summary>
        /// This logs every file that we have ever gotten BEFORE we start our work on it. It then moves each file in the drop folder
        /// to be accessed by AutoQC
        /// </summary>
        /// <param name="dropFolder"></param>
        /// <returns></returns>
        public static bool snapShot(System.IO.DirectoryInfo dropFolder)
        {
            //get all of the files

            System.IO.FileInfo[] files = dropFolder.GetFiles();

            

            List<System.IO.FileInfo> cleanfileList = utility.checkForSystemFiles(files.ToList<System.IO.FileInfo>());

            List<System.IO.FileInfo> toMove = new List<System.IO.FileInfo>();

            foreach (System.IO.FileInfo file in cleanfileList)
            {
                if (utility.isFileWritable(file))
                {
                    // Use the logger to log this
                    
                    System.IO.DirectoryInfo logsDirectory = new System.IO.DirectoryInfo(@"\\cob-hds-1\compression\QC\QCing\otherFiles\logs\OverseerLogs\");
                    
                    //USED FOR TESTING
                    //System.IO.DirectoryInfo logsDirectory = new System.IO.DirectoryInfo(@"C:\Users\BagpipesJohnson\Desktop\testing\Target");
                    
                    logger.saveToTXT("FilesReceived", logsDirectory, file.Name + '\t' + file.FullName + '\t' + file.CreationTime + '\t' + DateTime.Now + '\t' + file.Length + "\r\n");
                    logger.saveToTabDilimited("FilesReceived", logsDirectory, file.Name + '\t' + file.FullName + '\t' + file.CreationTime + '\t' + DateTime.Now + '\t' + file.Length + "\r\n");

                    // Create the metaData for the AutoQC bot to use
                    toMove.Add(file);
                }
            }
            taskmaster.moveAfterSnapshot(toMove);

            return false;
        }
Beispiel #3
0
        static void WalkDirectoryTree(System.IO.DirectoryInfo root)
        {
            System.IO.FileInfo[] files = null;
            System.IO.DirectoryInfo[] subDirs = null;

            // First, process all the files directly under this folder
            try
            {
                files = root.GetFiles("*.*");
            }
            // This is thrown if even one of the files requires permissions greater
            // than the application provides.
            catch (UnauthorizedAccessException e)
            {
                // This code just writes out the message and continues to recurse.
                // You may decide to do something different here. For example, you
                // can try to elevate your privileges and access the file again.
                log.Add(e.Message);
            }

            catch (System.IO.DirectoryNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }

            if (files != null)
            {
                foreach (System.IO.FileInfo fi in files) //search for files within the directories
                {
                    // In this example, we only access the existing FileInfo object. If we
                    // want to open, delete or modify the file, then
                    // a try-catch block is required here to handle the case
                    // where the file has been deleted since the call to TraverseTree().
                    if (fi.Name.Contains(".mp3"))
                    {
                        Console.WriteLine(fi.Name); //<--Uncomment this to write individual files in directories to Console
                    }
                    /*
                    String s = fi.FullName;
                    */
                }

                // Now find all the subdirectories under this directory.
                subDirs = root.GetDirectories(); //<------HERE!!!!!

                /**/
                foreach (System.IO.DirectoryInfo dirInfo in subDirs)
                {
                    // Resursive call for each subdirectory.
                    //Console.WriteLine(dirInfo.FullName);
                    /*
                    WHEN CALLING WalkDirectoryTree(dirInfo) BELOW:
                    The specified path, file name, or both are too long. 
                    The fully qualified file name must be less than 260 characters,
                    and the directory name must be less than 248 characters.
                    */
                    WalkDirectoryTree(dirInfo); //<--Uncomment this to recurse through the next level of subdirectories
                }
                /**/
            }
    static string FindPath(string foundPath, System.IO.DirectoryInfo root, string file)
    {
        System.IO.FileInfo[] files = null;
        System.IO.DirectoryInfo[] subDirs = null;

        try
        {
            files = root.GetFiles(file);
            subDirs = root.GetDirectories();
        }
        catch
        {
            return foundPath;
        }

        foreach (var f in files)
        {
            return f.FullName;
        }

        foreach (var sd in subDirs)
        {
            foundPath = FindPath(foundPath, sd, file);
            if (foundPath != "")
                return foundPath;
        }

        return foundPath;
    }
 private void scanFolder(System.IO.DirectoryInfo dirInfo, System.Collections.ArrayList list)
 {
     FileInfo[] files = dirInfo.GetFiles("*.ascx|*.aspx");
     foreach (var file in files)
     {
         if(scanFile(file)) list.Add(file);
     }
 }
        // add the move code
        /// <summary>
        /// This moves a specified file to a new location. 
        /// </summary>
        /// <param name="file">The complete file name--including the path-- of the file to be moved</param>
        /// <param name="endLocation">The Path to the target directory</param>
        /// <returns>Returns 0 on error, and 1 on a success</returns>
        static public string moveFile(System.IO.FileInfo file, System.IO.DirectoryInfo endLocation)
        {
            try
            {
                //check to see if the file is exclusively writable
                if (!isFileWritable(file))
                {
                    throw new IOException("File is not free to move");
                }

                if (!Directory.Exists(endLocation.FullName))
                {
                    Directory.CreateDirectory(endLocation.FullName);
                }
                string shortFileName = file.Name;
                string endLocationWithFile = endLocation + shortFileName;

                if(File.Exists(endLocationWithFile))
                {
                // Meant to over-ride duplicates to avoid exceptions
                System.IO.File.Delete(endLocationWithFile);
                }

                System.IO.File.Move(file.FullName, endLocationWithFile);
                System.Threading.Thread.Sleep(1000);
                //FileInfo deliveredFile = new FileInfo(endLocationWithFile);

                //if (Joshua.isFileInDirectory(endLocation, deliveredFile))
                //{
                //    Joshua.AddToDeliveredReport(deliveredFile);
                //}

                System.IO.FileInfo[] filesInDirectory = endLocation.GetFiles();
                foreach (System.IO.FileInfo temp in filesInDirectory)
                {
                    if (temp.Name == shortFileName)
                    {
                        
                        return "Passed";
                    }
                }
                
                // The file we sent over has not gotten to the correct directory....something went wrong!
                throw new IOException("File did not reach destination");

            }
            catch (Exception e)
            {
                if (e.Message.Contains("not free") || e.Message.Contains("being used"))
                {
                    logger.writeErrorLog("File was not free to move: " + file.Name);
                    return "File not free to move";
                }
                //Something went wrong, return a fail;
                logger.writeErrorLog("File could not be moved:" + file.Name);
                return "Did Not Arrive";
            }
        }
Beispiel #7
0
        static void WalkDirectoryTree(System.IO.DirectoryInfo root)
        {
            char start = root.FullName[0];

            foreach (var ef in _excludeFolders)
            {
                if (root.FullName.ToLower().Contains(ef.ToLower())) return;
            }

            System.IO.FileInfo[] files = null;
            System.IO.DirectoryInfo[] subDirs = null;

            // First, process all the files directly under this folder
            try
            {
                files = root.GetFiles("*.config");
            }
            // This is thrown if even one of the files requires permissions greater
            // than the application provides.
            catch (UnauthorizedAccessException e)
            {
                // This code just writes out the message and continues to recurse.
                // You may decide to do something different here. For example, you
                // can try to elevate your privileges and access the file again.
                //log.Add(e.Message);
            }

            catch (System.IO.DirectoryNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }

            if (files != null)
            {
                foreach (System.IO.FileInfo fi in files)
                {
                    Console.WriteLine(fi.FullName);
                    var fileDic = fi.Directory.FullName;
                    var newFileDic = _targetFolder + fileDic.Replace(_sourceDrive + @":\", "");
                    Console.WriteLine(newFileDic);
                    if (!Directory.Exists(newFileDic))
                    {
                        DirectoryInfo di = Directory.CreateDirectory(newFileDic);
                    }
                    var newFile = _targetFolder + fi.FullName.Replace(_sourceDrive + @":\", "");
                    File.Copy(fi.FullName, newFile);
                }

                // Now find all the subdirectories under this directory.
                subDirs = root.GetDirectories();

                foreach (System.IO.DirectoryInfo dirInfo in subDirs)
                {
                    // Resursive call for each subdirectory.
                    WalkDirectoryTree(dirInfo);
                }
            }
        }
	private void GetListing (System.IO.DirectoryInfo info)
	{
		try {
			GetListing (info, info.GetFiles (), recurse);
		} catch (System.UnauthorizedAccessException) {
			System.Console.WriteLine ("Unable to access directory {0}", info.FullName);
		} catch (System.Exception e) {
			System.Console.WriteLine ("{0}", e.ToString ());
		}
	}
Beispiel #9
0
        static void WalkDirectoryTree(System.IO.DirectoryInfo root, String newRoot)
        {
            System.IO.FileInfo[] files = null;
            System.IO.DirectoryInfo[] subDirs = null;

            // First, process all the files directly under this folder
            try
            {
                files = root.GetFiles("*.*");
            }
            // This is thrown if even one of the files requires permissions greater
            // than the application provides.
            catch (UnauthorizedAccessException e)
            {
                Console.WriteLine(e.Message);
            }

            catch (System.IO.DirectoryNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }

            if (files != null)
            {
                foreach (System.IO.FileInfo fi in files)
                {
                    Console.WriteLine(fi.FullName);
                    if (fi.FullName.Contains(".mht"))
                    {
                        String content = System.IO.File.ReadAllText(fi.FullName, Encoding.Default);
                        content = content.Replace("=\r", "");
                        String oldRoot = "C:\\Users\\&#1042;&#1086;&#1088;&#1086;&#1073;&#1100;&#1077;&#1074;&#1072;";
                        //TODO
                        //newRoot = "FireEagle";
                        content = content.Replace(oldRoot, newRoot);
                        //Console.Read();
                        //StreamWriter writer = new StreamWriter(fi.FullName, false, Encoding.Default);
                        //writer.Write(content);
                        //writer.Close();
                        System.IO.File.WriteAllText(fi.FullName, content, Encoding.UTF8);
                        Console.WriteLine(fi.FullName);
                    }
                }

                // Now find all the subdirectories under this directory.
                subDirs = root.GetDirectories();

                foreach (System.IO.DirectoryInfo dirInfo in subDirs)
                {
                    // Resursive call for each subdirectory.
                    WalkDirectoryTree(dirInfo, newRoot);
                }
            }
        }
Beispiel #10
0
        public static void WalkDirectoryTree(System.IO.DirectoryInfo root, XElement rootDir)
        {
            XElement dir = new XElement("dir");
            dir.SetAttributeValue("name", root.Name);

            rootDir.Add(dir);

            System.IO.FileInfo[] files = null;
            System.IO.DirectoryInfo[] subDirs = null;

            // First, process all the files directly under this folder
            try
            {
                files = root.GetFiles("*.*");
            }
            // This is thrown if even one of the files requires permissions greater
            // than the application provides.
            catch (UnauthorizedAccessException e)
            {
                // This code just writes out the message and continues to recurse.
                // You may decide to do something different here. For example, you
                // can try to elevate your privileges and access the file again.
                // log.Add(e.Message);
            }

            catch (System.IO.DirectoryNotFoundException e)
            {
                //Console.WriteLine(e.Message);
            }

            if (files != null)
            {
                foreach (System.IO.FileInfo fi in files)
                {
                    // In this example, we only access the existing FileInfo object. If we
                    // want to open, delete or modify the file, then
                    // a try-catch block is required here to handle the case
                    // where the file has been deleted since the call to TraverseTree().
                    XElement file = new XElement("file");
                    file.SetAttributeValue("name", fi.Name);
                    dir.Add(file);

                }

                // Now find all the subdirectories under this directory.
                subDirs = root.GetDirectories();

                foreach (System.IO.DirectoryInfo dirInfo in subDirs)
                {
                    // Resursive call for each subdirectory.
                    WalkDirectoryTree(dirInfo, rootDir);
                }
            }
        }
 public void Empty(System.IO.DirectoryInfo directory)
 {
     foreach (System.IO.FileInfo file in directory.GetFiles())
     {
         file.Delete();
     }
     foreach (System.IO.DirectoryInfo subDirectory in directory.GetDirectories())
     {
         subDirectory.Delete(true);
     }
 }
Beispiel #12
0
 /// <summary>
 /// 拷贝目录下的所有文件到目的目录。
 /// </summary>
 /// <param name="path">源路径</param>
 /// <param name="desPath">目的路径</param>
 public static void CopyFile(System.IO.DirectoryInfo path, string desPath)
 {
     string sourcePath = path.FullName;
     System.IO.FileInfo[] files = path.GetFiles();
     foreach (System.IO.FileInfo file in files)
     {
         string sourceFileFullName = file.FullName;
         string destFileFullName = sourceFileFullName.Replace(sourcePath, desPath);
         file.CopyTo(destFileFullName, true);
     }
 }
        /// <summary>
        /// Backups a directory.
        /// </summary>
        /// <param name="root">The root.</param>
        public void BackupDirectory(System.IO.DirectoryInfo root)
        {
            System.IO.FileInfo[] files = null;
            System.IO.DirectoryInfo[] subDirs = null;

            try
            {
                string dirPath = root.FullName;

                files = root.GetFiles();
                subDirs = root.GetDirectories();

                if (0 == files.Length && 0 == subDirs.Length)
                {
                    string blobFolderPath = Common.GetBlobPath(dirPath);
                    this.BlobCreate(dirPath, dirPath, blobFolderPath);

                    return;
                }

                if (files.Length > 0)
                {
                    foreach (System.IO.FileInfo fi in files)
                    {
                        string filePath = fi.FullName;
                        string blobPath = Common.GetBlobPath(filePath);

                        this.BlobCreate(dirPath, filePath, blobPath);
                    }
                }

                if (subDirs.Length > 0)
                {
                    foreach (System.IO.DirectoryInfo dirInfo in subDirs)
                    {
                        // Resursive call for each subdirectory.
                        this.BackupDirectory(dirInfo);
                    }
                }
            }
            catch (System.UnauthorizedAccessException)
            {
            }
            catch (System.IO.DirectoryNotFoundException)
            {
            }
            catch (System.Exception)
            {
            }
        }
 public List<string> DirectoryWalkThroughLocalList(System.IO.DirectoryInfo di, string filePath, string extension, List<string> localeList)
 {
     System.IO.FileInfo[] files = di.GetFiles("*" + extension);
     foreach (System.IO.FileInfo fi in files)
     {
         string code = GetLanguageCode(fi.Name.Replace(extension, ""));
         if (code != "")
             localeList.Add(code);
     }
     foreach (System.IO.DirectoryInfo di_child in di.GetDirectories())
     {
         localeList = DirectoryWalkThroughLocalList(di_child, filePath, extension, localeList);
     }
     return localeList;
 }
 private long Size(System.IO.DirectoryInfo Dir)
 {
     long size = 0;
     System.IO.FileSystemInfo[] filelist = Dir.GetFileSystemInfos();
     System.IO.FileInfo[] fileInfo;
     fileInfo = Dir.GetFiles("*", System.IO.SearchOption.AllDirectories);
     for (int i = 0; i < fileInfo.Length; i++)
     {
         try
         {
             size += fileInfo[i].Length;
         }
         catch { }
     }
     return size;
 }
 // cache
 private void ClearFolder(System.IO.DirectoryInfo folder)
 {
     foreach (System.IO.FileInfo file in folder.GetFiles())
     {
         try
         {
             file.Delete();
         }
         catch (Exception)
         {
         }
     }
     foreach (System.IO.DirectoryInfo subfolder in folder.GetDirectories())
     {
         ClearFolder(subfolder);
     }
 }
Beispiel #17
0
        public void WalkDirectoryTree(System.IO.DirectoryInfo root, PSVitaMusicWizard.FileTypes.FileExtensions extension)
        {
            System.IO.FileInfo[] files = null;
            System.IO.DirectoryInfo[] subDirs = null;

            // First, process all the files directly under this folder
            try
            {
                files = root.GetFiles(string.Format("*.{0}", Enum.GetName(typeof(PSVitaMusicWizard.FileTypes.FileExtensions), extension)));
            }
            // This is thrown if even one of the files requires permissions greater
            // than the application provides.
            catch (UnauthorizedAccessException e)
            {
                // This code just writes out the message and continues to recurse.
                // You may decide to do something different here. For example, you
                // can try to elevate your privileges and access the file again.
                log.Add(e.Message);
            }

            catch (System.IO.DirectoryNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }

            if (files != null)
            {
                foreach (System.IO.FileInfo fi in files)
                {
                    // In this example, we only access the existing FileInfo object. If we
                    // want to open, delete or modify the file, then
                    // a try-catch block is required here to handle the case
                    // where the file has been deleted since the call to TraverseTree().
                    CreateMusicFiles(fi.FullName);
                }
                // Now find all the subdirectories under this directory.
                subDirs = root.GetDirectories();

                foreach (System.IO.DirectoryInfo dirInfo in subDirs)
                {
                    //Console.WriteLine(string.Format("DIRECTORY: {0}", dirInfo.FullName));
                    // Resursive call for each subdirectory.
                    WalkDirectoryTree(dirInfo, extension);
                }
            }
        }
Beispiel #18
0
 public static long countDirSize(System.IO.DirectoryInfo dir)
 {
     long size = 0;
     FileInfo[] files = dir.GetFiles();
     //通过GetFiles方法,获取目录中所有文件的大小
     foreach (System.IO.FileInfo info in files)
     {
         size += info.Length;
     }
     DirectoryInfo[] dirs = dir.GetDirectories();
     //获取目录下所有文件夹大小,并存到一个新的对象数组中
     foreach (DirectoryInfo dirinfo in dirs)
     {
         size += countDirSize(dirinfo);
     }
     return size;
 }
Beispiel #19
0
        static void WalkDirectoryTree(System.IO.DirectoryInfo root)
        {
            System.IO.FileInfo[] files = null;
            System.IO.DirectoryInfo[] subDirs = null;

            // Сначала обрабатывает все файлы внутри этой папки.
            try
            {
                files = root.GetFiles("*.*");
            }
            // Выполняется даже если один из файлов требует разрешения большей степени чем обеспечивает приложение.
            catch (UnauthorizedAccessException e)
            {
                // Этот код просто выписывает сообщение и продолжает рекурсировать.
                // Можно попробывать что-нибудь другое. 
                // Например, можно попробывать повысить свои привелегиии и добраться до файла снова.
                log.Add(e.Message);
            }

            catch (System.IO.DirectoryNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }

            if (files != null)
            {
                foreach (System.IO.FileInfo fi in files)
                {
                    // В этом примере мы только получаем доступ к существующему FileInfo object.
                    // Если мы хотим открыть, изменить или модифицировать файл, тогда
                    // рекомендуется блок "try-catch" чтоб решить задачу где файл
                    // был удален после вызова TraverseTree().
                    Console.WriteLine(fi.FullName);
                }

                // Теперь найдем подфайлы под этим файлом.
                subDirs = root.GetDirectories();

                foreach (System.IO.DirectoryInfo dirInfo in subDirs)
                {
                    // Рекурсивный вызов для всех подфайлов.
                    WalkDirectoryTree(dirInfo);
                }
            }
        }
Beispiel #20
0
        static void UploadFilesToLibrary(ClientContext ctx, Folder spFolder, System.IO.DirectoryInfo localFolder)
        {
            foreach (var localFile in localFolder.GetFiles())
            {
                File file = spFolder.GetFile(localFile.Name);
                if (file != null)
                    file.CheckOut();
                Console.WriteLine("> File: " + localFile.Name);
                file = spFolder.UploadFile(localFile.Name, localFile.FullName, true);
                file.PublishFileToLevel(FileLevel.Published);
            }

            foreach (var localSubFolder in localFolder.GetDirectories())
            {
                Console.WriteLine("> Folder: " + localSubFolder.Name);
                Folder spSubFolder = spFolder.EnsureFolder(localSubFolder.Name);
                UploadFilesToLibrary(ctx, spSubFolder, localSubFolder);
            }
        }
Beispiel #21
0
    TreeNode OutputDirectory(System.IO.DirectoryInfo directory, TreeNode parentNode)
    {
        // validate param
        if (directory == null) return null;

        // create a node for this directory
        TreeNode DirNode = new TreeNode(directory.Name);

        // get subdirectories of the current directory
        System.IO.DirectoryInfo[] SubDirectories = directory.GetDirectories();

        // output each subdirectory
        for (int DirectoryCount = 0; DirectoryCount < SubDirectories.Length; DirectoryCount++)
        {
            if(!SubDirectories[DirectoryCount].Extension.Contains(".svn"))
                OutputDirectory(SubDirectories[DirectoryCount], DirNode);
        }

        // output the current directories files
        System.IO.FileInfo[] Files = directory.GetFiles();

        for (int FileCount = 0; FileCount < Files.Length; FileCount++)
        {
            if(Files[FileCount].Extension.EndsWith("cs") || Files[FileCount].Extension.EndsWith("sql"))
            DirNode.ChildNodes.Add(new TreeNode(Files[FileCount].Name));
        }

        // if the parent node is null, return this node
        // otherwise add this node to the parent and return the parent
        if (parentNode == null)
        {
            return DirNode;
        }
        else
        {
            parentNode.ChildNodes.Add(DirNode);
            return parentNode;
        }
    }
Beispiel #22
0
        static void WalkDirectoryTree(System.IO.DirectoryInfo root, string line)
        {
            System.IO.FileInfo[] files = null;
            System.IO.DirectoryInfo[] subDirs = null;

            files = root.GetFiles("*.config", SearchOption.TopDirectoryOnly);
            if (files != null)
            {
                foreach (System.IO.FileInfo fi in files)
                {
                    //Console.WriteLine(fi.FullName);
                    System.IO.StreamReader file = new System.IO.StreamReader(fi.FullName);
                    string aline;
                    while ((aline = file.ReadLine()) != null)
                    {
                        if (aline.Contains(line))
                        {
                            _stringIndex += "&&&&&&&&&";
                            _stringIndex += fi.FullName;
                            _stringIndex += "---------";
                            _stringIndex += aline;
                        }
                    }

                    file.Close();
                }

            }
            // Now find all the subdirectories under this directory.
            subDirs = root.GetDirectories();

            foreach (System.IO.DirectoryInfo dirInfo in subDirs)
            {
                // Resursive call for each subdirectory.
                WalkDirectoryTree(dirInfo, line);
            }
        }
 protected override void ParseFiles(System.IO.DirectoryInfo folder, string rootPath)
 {
     FileInfo[] files = folder.GetFiles();
     foreach (FileInfo file in files)
     {
         string filePath = folder.FullName.Replace(rootPath, "");
         if (filePath.StartsWith("\\"))
         {
             filePath = filePath.Substring(1);
         }
         if (file.Extension.ToLowerInvariant() != ".dnn")
         {
             if (string.IsNullOrEmpty(_SubFolder))
             {
                 AddFile(Path.Combine(filePath, file.Name));
             }
             else
             {
                 filePath = Path.Combine(filePath, file.Name);
                 AddFile(filePath, Path.Combine(_SubFolder, filePath));
             }
         }
     }
 }
Beispiel #24
0
        static string FindFileFullPath(System.IO.DirectoryInfo process_root, string file_name, string ext_name)
        {
            System.IO.FileInfo[] files = null;
            System.IO.DirectoryInfo[] subDirs = null;

            // First, process all the files directly under this folder
            try
            {
                string target_file_set = file_name + "*" + ext_name;
                files = process_root.GetFiles(target_file_set);
            }
            catch (UnauthorizedAccessException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (System.IO.DirectoryNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }

            // Walk all target JPG to find txt.
            if (files != null)
            {
                foreach (System.IO.FileInfo fi in files)
                {
                    return fi.FullName;
                }

                subDirs = process_root.GetDirectories();
                foreach (System.IO.DirectoryInfo dirInfo in subDirs)
                {
                    FindFileFullPath(dirInfo, file_name, ext_name);
                }
            }
            return ""; //not found
        }
		public static void EmptyFolder(System.IO.DirectoryInfo directory)
		{
			foreach (System.IO.FileInfo file in directory.GetFiles()) file.Delete();
			foreach (System.IO.DirectoryInfo subDirectory in directory.GetDirectories()) subDirectory.Delete(true);
		}
        protected void WalkDirectoryTree(System.IO.DirectoryInfo root, string fileSpec, List<KeyValuePair<string, string>> findReplaceList) {
            System.IO.FileInfo[] files = null;
            System.IO.DirectoryInfo[] subDirs = null;

            // First, process all the files directly under this folder 
            try {
                files = root.GetFiles(fileSpec);
            }
            // This is thrown if even one of the files requires permissions greater 
            // than the application provides. 
            catch (UnauthorizedAccessException e) {
                // This code just writes out the message and continues to recurse. 
                // You may decide to do something different here. For example, you 
                // can try to elevate your privileges and access the file again.
                MessageService.WriteMessage(e.Message);
            }

            catch (System.IO.DirectoryNotFoundException e) {
                MessageService.WriteMessage(e.Message);
            }

            if (files != null) {
                foreach (System.IO.FileInfo fi in files) {
                    // In this example, we only access the existing FileInfo object. If we 
                    // want to open, delete or modify the file, then 
                    // a try-catch block is required here to handle the case 
                    // where the file has been deleted since the call to TraverseTree().
                    MessageService.WriteMessage(fi.FullName);
                    foreach (KeyValuePair<string, string> kvp in findReplaceList) {
                        try {
                            FindAndReplace(fi.FullName, kvp);
                        }
                        catch (Exception ex) {
                            MessageService.WriteMessage(ex.Message);
                        }
                    }
                }

                // Now find all the subdirectories under this directory.
                subDirs = root.GetDirectories();

                foreach (System.IO.DirectoryInfo dirInfo in subDirs) {
                    // Resursive call for each subdirectory.
                    WalkDirectoryTree(dirInfo, fileSpec, findReplaceList);
                }
            }
        }
Beispiel #27
0
        static void WalkDirectoryTree(System.IO.DirectoryInfo root)
        {
            System.IO.FileInfo[] files = null;
            System.IO.DirectoryInfo[] subDirs = null;

            WMPLib.WindowsMediaPlayer w = new WMPLib.WindowsMediaPlayer();

            try
            {
                files = root.GetFiles("*.*");
            }
            // This is thrown if even one of the files requires permissions greater
            // than the application provides.
            catch (UnauthorizedAccessException e)
            {
                log.Add(e.Message);
            }

            catch (System.IO.DirectoryNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }

            if (files != null)
            {
                foreach (System.IO.FileInfo fi in files)
                {
                    if (fi.Extension.ToLower() == ".mp3")
                    {
                        Console.WriteLine(fi.FullName);
                        WMPLib.IWMPMedia m = w.newMedia(fi.FullName);
                        if (m != null || m.duration != null)
                        {
                            if (m.duration >= dblMinDuration)
                            {
                                sourceMp3Files.Add(fi);
                            }
                        }

                    }
                }

                // Now find all the subdirectories under this directory.
                subDirs = root.GetDirectories();

                foreach (System.IO.DirectoryInfo dirInfo in subDirs)
                {
                    // Resursive call for each subdirectory.
                    WalkDirectoryTree(dirInfo);
                }
            }

            w.close();
        }
Beispiel #28
0
        internal void WalkDirectoryTree(System.IO.DirectoryInfo root, SampleFileEntry rootProperty)
        {
            try
            {
                // First try to get all the sub-directories before the files themselves.
                System.IO.DirectoryInfo[] directories = root.GetDirectories();
                if (null != directories && (directories.Length > 0))
                {
                    foreach (System.IO.DirectoryInfo directory in directories)
                    {
                        // Resursive call for each subdirectory.
                        SampleFileEntry subProperty = 
                            new SampleFileEntry(directory.Name, directory.FullName);
                        WalkDirectoryTree(directory, subProperty);
                        rootProperty.AddChildSampleFile(subProperty);
                    }
                }

                // Secondly, process all the files directly under this folder 
                System.IO.FileInfo[] dynamoFiles = null;
                dynamoFiles = root.GetFiles("*.dyn", System.IO.SearchOption.TopDirectoryOnly);

                if (null != dynamoFiles && (dynamoFiles.Length > 0))
                {
                    foreach (System.IO.FileInfo file in dynamoFiles)
                    {
                        if (sampleFolderPath == null)
                        {                            
                            sampleFolderPath = Path.GetDirectoryName(file.FullName);
                        }
                        // Add each file under the root directory property list.
                        rootProperty.AddChildSampleFile(new SampleFileEntry(file.Name, file.FullName));
                    }
                }
            }
            catch (Exception)
            {
                // Perhaps some permission problems?
            }
        }
 private void Empty(System.IO.DirectoryInfo directory)
 {
     foreach (System.IO.FileInfo file in directory.GetFiles()) file.Delete();
 }
Beispiel #30
0
        /// <summary>Lists all files (not subdirectories) in the
        /// directory.  This method never returns null (throws
        /// {@link IOException} instead).
        /// 
        /// </summary>
        /// <throws>  NoSuchDirectoryException if the directory </throws>
        /// <summary>   does not exist, or does exist but is not a
        /// directory.
        /// </summary>
        /// <throws>  IOException if list() returns null  </throws>
        public static System.String[] ListAll(System.IO.DirectoryInfo dir)
        {
            if (!dir.Exists)
            {
                throw new NoSuchDirectoryException("directory '" + dir.FullName + "' does not exist");
            }
            // Exclude subdirs, only the file names, not the paths
            System.IO.FileInfo[] files = dir.GetFiles();
            System.String[] result = new System.String[files.Length];
            for (int i = 0; i < files.Length; i++)
            {
                result[i] = files[i].Name;
            }

            // no reason to return null, if the directory cannot be listed, an exception
            // will be thrown on the above call to dir.GetFiles()
            // use of LINQ to create the return value array may be a bit more efficient

            return result;
        }