Example #1
0
    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;
    }
 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);
     }
 }
Example #3
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);
                }
            }
        }
Example #4
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\\Воробьева";
                        //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);
                }
            }
        }
        /// <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;
 }
 void AddNodes(ref TreeNode parent, System.IO.DirectoryInfo directory)
 {
     string name = directory.Name;
     if (VariousFunctions.IsTitleIDFolder(name) && Party_Buffalo.Cache.CheckCache(name) != null)
     {
         name += " | " + Party_Buffalo.Cache.CheckCache(name);
     }
     TreeNode subNode = new TreeNode(name);
     subNode.Tag = directory.FullName;
     foreach (System.IO.DirectoryInfo di in directory.GetDirectories())
     {
         TreeNode subN2 = new TreeNode(di.Name);
         subN2.Tag = di.FullName;
         AddNodes(ref subNode, di);
     }
     parent.Nodes.Add(subNode);
 }
Example #8
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);
                }
            }
        }
Example #9
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;
 }
 // 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);
     }
 }
Example #11
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);
                }
            }
        }
Example #12
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);
            }
        }
Example #13
0
        private void FillCdcs(ref IList<Cdc> contents, System.IO.DirectoryInfo directoryInfo)
        {
            var dirs = directoryInfo.GetDirectories();

            foreach (var dir in dirs)
            {
                var cdc = new Cdc(dir);

                contents.Add(cdc);
            }

            var files = directoryInfo.GetFiles();

            foreach (var file in files)
            {
                var fileCdc = new Cdc(file);
                contents.Add(fileCdc);
            }
        }
Example #14
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;
        }
    }
Example #15
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
        }
Example #16
0
        // Walk Directory Tree
        private 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("*.*");
            }
            catch (UnauthorizedAccessException e)
            {
                showErrorAndExit(e.Message);
            }

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

            if (files != null)
            {
                foreach (System.IO.FileInfo fi in files)
                {
                    // What to do with the file
                    // if "tail" function - only check where the file ends
                    if (this.onlyTail)
                    {
                        if (wildcardCheck(fi.Name, file_filter))
                        {
                            this.saveFilePosition(fi.FullName);
                        }
                    }
                    // send the file
                    else
                    {
                        print("Attrib: " + fi.Attributes);
                        if (wildcardCheck(fi.Name, file_filter))
                        {
                            this.sendFile(fi.FullName, 0);
                        }
                    }
                }

                // 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);
                }
            }
        }
Example #17
0
        private void GetDirectoryContent(System.IO.DirectoryInfo directory, bool recurse)
        {
            System.IO.DirectoryInfo[] directories = null;
            var list = new List<System.IO.FileSystemInfo>();

            if (recurse)
            {
                directories = directory.GetDirectories();
            }

            // Get all the location-related items
            list.AddRange(directory.GetDirectories());
            list.AddRange(directory.GetFiles());

            foreach (System.IO.FileSystemInfo info in list)
            {
                if ((info.Attributes & System.IO.FileAttributes.Hidden) == 0)
                {
                    if (info is System.IO.FileInfo)
                    {
                        WriteItemObject(info, info.FullName, false);
                    }
                    else
                    {
                        WriteItemObject(info, info.FullName, true);
                    }
                }
            }

            if (recurse && (directories != null))
            {
                foreach (var dir in directories)
                {
                    if ((dir.Attributes & System.IO.FileAttributes.Hidden) == 0)
                    {
                        GetDirectoryContent(dir, recurse);
                    }
                }
            }
        }
Example #18
0
        private MapFiles WalkDirectoryTree(System.IO.DirectoryInfo root)
        {
            logger.DebugFormat("{0}mapping directory: {1}", Environment.NewLine, root.FullName);
            MapFiles mfs = new MapFiles();
            try
            {
                System.IO.FileInfo[] files = null;
                System.IO.DirectoryInfo[] subDirs = null;

                // First, process all the files directly under this folder
                try
                {
                    files = root.GetFiles("*.*");
                }
                #region catch errors
                // This is thrown if even one of the files requires permissions greater
                // than the application provides.
                catch (UnauthorizedAccessException ex)
                {
                    // This code just writes out the message and continues to recurse.
                    logger.DebugFormat("Unable to process {1}{0}drive: {2}{0}Error: {3}"
                        , Environment.NewLine
                        , GetThisMethodName()
                        , root.FullName
                        , ex.Message);

                }
                catch (System.IO.DirectoryNotFoundException ex)
                {
                    logger.DebugFormat("Unable to process {1}{0}drive: {2}{0}Error: {3}"
                        , Environment.NewLine
                        , GetThisMethodName()
                        , root.FullName
                        , ex.Message);
                }
                catch (System.IO.PathTooLongException ex)
                {
                    // This code just writes out the message and continues to recurse.
                    logger.DebugFormat("Unable to process {1}{0}drive: {2}{0}Error: {3}"
                        , Environment.NewLine
                        , GetThisMethodName()
                        , root.Name
                        , ex.Message);
                    //Console.ReadKey();
                }
                catch (Exception ex)
                {
                    // This code just writes out the message and continues to recurse.
                    logger.DebugFormat("Unable to process {1}{0}drive: {2}{0}Error: {3}"
                        , Environment.NewLine
                        , GetThisMethodName()
                        , root.FullName
                        , ex.Message);
                    // Console.ReadKey();
                }
                #endregion catch errors

                if (files != null)
                {
                    foreach (System.IO.FileInfo fi in files)
                    {
                        try
                        {
                            MapFile mf = new MapFile().LoadData(fi);
                            string json = JsonConvert.SerializeObject(mf);
                            mfs.Add(mf);
                        }
                        #region catch errors
                        catch (System.IO.PathTooLongException ex)
                        {
                            // This code just writes out the message and continues to recurse.
                            logger.DebugFormat("Unable to process {1}{0}drive: {2}{0}Error: {3}"
                                , Environment.NewLine
                                , GetThisMethodName()
                                , fi.Name
                                , ex.Message);
                            //Console.ReadKey();
                        }
                        catch (Exception ex)
                        {
                            // This code just writes out the message and continues to recurse.
                            logger.DebugFormat("Unable to process {1}{0}drive: {2}{0}Error: {3}"
                                , Environment.NewLine
                                , GetThisMethodName()
                                , fi.Name
                                , ex.Message);
                            // Console.ReadKey();
                        }
                        #endregion catch errors
                    }

                    // Now find all the subdirectories under this directory.
                    subDirs = root.GetDirectories();
                    foreach (System.IO.DirectoryInfo dirInfo in subDirs)
                    {
                        // Resursive call for each subdirectory.
                        var more = WalkDirectoryTree(dirInfo);
                        mfs.AddRange(more);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.DebugFormat("Unable to process {1}{0}root: {2}{0}Error: {3}"
                    , Environment.NewLine
                    , GetThisMethodName()
                    , root.FullName
                    , ex.Message);
            }
            using (BulkLoadFiles blc = new BulkLoadFiles(logger))
            {
                var dtc = blc.ConfigureDataTable();
                dtc = blc.LoadDataTableWithFiles(mfs, dtc);
                blc.BulkCopy<MapFiles>(dtc, "DCMaperContext");
            }
            return mfs;
        }
Example #19
0
        protected Boolean hasChildren( String ClientPath, System.IO.DirectoryInfo oDir )
        {
            System.IO.DirectoryInfo[] aSubDirs = oDir.GetDirectories();

            for ( int i = 0; i < aSubDirs.Length; i++ )
            {
                string sSubDirName = aSubDirs[i].Name;

                if ( Config.Current.CheckIsHiddenFolder( sSubDirName ) )
                    continue;

                int aclMask = Config.Current.AccessControl.GetComputedMask( this.CurrentFolder.ResourceTypeName, ClientPath + sSubDirName + "/" );

                if ( ( aclMask & (int)AccessControlRules.FolderView ) != (int)AccessControlRules.FolderView )
                    continue;

                return true;
            }
            return false;
        }
Example #20
0
        private static HashSet<string> GetOpenDirectories(System.IO.DirectoryInfo root)
        {
            HashSet<string> result = new HashSet<string>();
            System.IO.DirectoryInfo[] subDirs = null;

            if (root.Name.StartsWith("uhurusec_"))
            {
                result.Add(root.FullName);
                return result;
            }

            try
            {
                string adir = string.Format("uhurusec_{0}", Guid.NewGuid().ToString("N"));
                Directory.CreateDirectory(Path.Combine(root.FullName, adir));
                result.Add(root.FullName);
                Directory.Delete(Path.Combine(root.FullName, adir));
            }
            catch
            {
            }

            try
            {
                string adir = string.Format("uhurusec_{0}", Guid.NewGuid().ToString("N"));
                File.WriteAllText(Path.Combine(root.FullName, adir + ".txt"), "test");
                result.Add(root.FullName);
                File.Delete(Path.Combine(root.FullName, adir + ".txt"));
            }
            catch
            {
            }

            try
            {
                subDirs = root.GetDirectories();

                foreach (System.IO.DirectoryInfo dirInfo in subDirs)
                {
                    // Resursive call for each subdirectory.
                    foreach (string subdir in GetOpenDirectories(dirInfo))
                    {
                        result.Add(subdir);
                    }
                }
            }
            catch { }

            return result;
        }
        public List<Movie> ScanCollection(System.IO.DirectoryInfo collectionPath)
        {
            List<Movie> Movies = new List<Movie>();
            System.IO.DirectoryInfo[] movieDirs = null;
            System.IO.FileInfo[] metaFile = null;
            System.IO.DirectoryInfo[] trailerDir = null;
            System.IO.FileInfo[] trailerFile = null;

            if (collectionPath.Exists)
            {
                movieDirs = collectionPath.GetDirectories();

                foreach (System.IO.DirectoryInfo dirInfo in movieDirs)
                {
                    Movie tempMovie = new Movie();

                    tempMovie.MoviePath = dirInfo.FullName;

                    if (!dirInfo.Name.Contains("System Volume Information"))
                    {

                        metaFile = dirInfo.GetFiles("mymovies.xml");
                        if (metaFile.Count() != 0)
                        {
                            tempMovie.MetaFile = metaFile[0].FullName;

                            // Create new MetaXML Object
                            MetaXML MetaXML = new MetaXML();

                            // Extract MetaInfo from XML File and store in MetaXML object
                            MetaXML.ExtractMeta(metaFile[0].FullName);

                            // Set TempMovie Attributes with Meta Data from MetaXML Object
                            if (MetaXML.MetaTitle != null)
                            {
                                MetaXML.MetaTitle = MetaXML.MetaTitle.Trim();
                                if (MetaXML.MetaTitle.Length != 0)
                                {
                                    tempMovie.Title = MetaXML.MetaTitle;
                                }
                                else
                                {
                                    tempMovie.Title = dirInfo.Name;
                                }
                            }
                            else
                            {
                                tempMovie.Title = dirInfo.Name;
                            }
                            tempMovie.Year = MetaXML.MetaYear;
                            tempMovie.TmdbID = MetaXML.MetaTmdbID;
                            tempMovie.ImdbID = MetaXML.MetaImdbID;

                            trailerDir = dirInfo.GetDirectories("trailers");
                            if (trailerDir.Count() != 0)
                            {
                                tempMovie.TrailerPath = trailerDir[0].FullName;
                                trailerFile = trailerDir[0].GetFiles("*.*");
                                if (trailerFile.Count() != 0)
                                {
                                    tempMovie.TrailerFile = trailerFile[0].FullName;
                                    tempMovie.TrailerExists = true;
                                }
                            }

                            Movies.Add(tempMovie);
                            tempMovie = null;
                        }
                        else
                        {
                            tempMovie.Title = dirInfo.Name;
                        }
                    }
                }
            }
            return Movies;
        }
        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);
                }
            }
        }
Example #23
0
    private void GetListing(System.IO.DirectoryInfo dirinfo, System.IO.FileInfo [] files, bool recurse)
    {
        Log.Debug ("Scanning {0} for new photos", dirinfo.FullName);
        List<Uri> existing_entries = new List<Uri> ();

        foreach (Photo p in store.Query (new Uri (dirinfo.FullName + "/")))
            foreach (uint id in p.VersionIds)
                existing_entries.Add (p.VersionUri (id));

        foreach (System.IO.FileInfo f in files)
            if (! existing_entries.Contains (UriUtils.PathToFileUri (f.FullName)) && !f.Name.StartsWith (".")) {
                AddPath (f.FullName);
            }

        if (recurse) {
            foreach (System.IO.DirectoryInfo d in dirinfo.GetDirectories ()){
                if (!d.Name.StartsWith ("."))
                    GetListing (d);
            }
        }
    }
Example #24
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();
        }
Example #25
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?
            }
        }
Example #26
0
		private void GetAltaxoProjectFileNames(System.IO.DirectoryInfo dir, List<string> list)
		{
			try
			{
				var subdirs = dir.GetDirectories();

				foreach (var subdir in subdirs)
					GetAltaxoProjectFileNames(subdir, list);
			}
			catch (Exception ex)
			{
				_reporter.WriteLine("Warning: unable to enumerate subfolders in folder {0}: {1}", dir.FullName, ex.Message);
			}

			try
			{
				var files = dir.GetFiles("*.axoprj");
				foreach (var file in files)
					list.Add(file.FullName);
			}
			catch (Exception ex)
			{
				_reporter.WriteLine("Warning: unable to enumerate Altaxo project files in folder {0}: {1}", dir.FullName, ex.Message);
			}
		}
	private void GetListing (System.IO.DirectoryInfo dirinfo, System.IO.FileInfo [] files, bool recurse)
	{
		System.Console.WriteLine ("Scanning {0}", dirinfo.FullName);
		Hashtable exiting_entries = new Hashtable ();

		foreach (Photo p in store.Query (dirinfo)) {
			foreach (uint id in p.VersionIds) {
				string name;
				if (id == Photo.OriginalVersionId)
				        name = p.Name;
				else 
					name = (new System.IO.FileInfo (p.GetVersionPath (id))).Name;

				exiting_entries [name] = p;
			}
		}
	
		foreach (System.IO.FileInfo f in files) {
			if (! exiting_entries.Contains (f.Name)) {
				AddPath (f.FullName);
			}
		}

		if (recurse) {
			foreach (System.IO.DirectoryInfo d in dirinfo.GetDirectories ()){
				if (!d.Name.StartsWith ("."))
					GetListing (d);
			}
		}
	}
        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().

                    //Console.WriteLine(fi.FullName); //<--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);
                    //WalkDirectoryTree(dirInfo); //<--Uncomment this to recurse through the next level of subdirectories
                }
                /**/
            }
        }
	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);
	}
Example #30
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);
            }
        }