当前位置: 首页>>代码示例>>C#>>正文


C# Folder.AddFolder方法代码示例

本文整理汇总了C#中Folder.AddFolder方法的典型用法代码示例。如果您正苦于以下问题:C# Folder.AddFolder方法的具体用法?C# Folder.AddFolder怎么用?C# Folder.AddFolder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Folder的用法示例。


在下文中一共展示了Folder.AddFolder方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DirectoryDFS

    private Folder DirectoryDFS(Folder folder)
    {
        try
        {
            var files = Directory.GetFiles(folder.Name);
            foreach (string item in files)
            {
                FileInfo fileinfo = new FileInfo(item);
                File file = new File(item, (int)fileinfo.Length);
                folder.AddFile(file);
            }

            var childFolders = Directory.GetDirectories(folder.Name);
            foreach (string item in childFolders)
            {
                Folder subFolder = new Folder(item);
                folder.AddFolder(subFolder);
                DirectoryDFS(subFolder);
            }
        }

        //catches the exceptions given if access restricted folder reached
        catch (UnauthorizedAccessException)
        {
        }

        return folder;
    }
开发者ID:hristo11111,项目名称:TelerikAcademy-HristoBratanov,代码行数:28,代码来源:FolderTree.cs

示例2: FillDirectoryTree

 private static void FillDirectoryTree(string path, Folder folder)
 {
     try
     {
         // Append files
         var files = Directory.GetFiles(path);
         foreach (var file in files)
         {
             string fileName = GetName(file);
             FileInfo fileInfo = new FileInfo(file);
             folder.AddFile(new File(fileName, fileInfo.Length));
         }
         // Append dirs recursively
         var dirs = Directory.GetDirectories(path);
         foreach (var dir in dirs)
         {
             string dirName = GetName(dir);
             Folder newFolder = new Folder(dirName);
             folder.AddFolder(newFolder);
             FillDirectoryTree(dir, newFolder);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
开发者ID:klimentt,项目名称:Telerik-Academy,代码行数:27,代码来源:FilesAndFolders.cs

示例3: TraverseDirectory

        private static void TraverseDirectory(Folder currentFolder)
        {
            try
            {
                DirectoryInfo currentDirecotoryInfo = new DirectoryInfo(currentFolder.Name);
                DirectoryInfo[] subDirectories = currentDirecotoryInfo.GetDirectories();

                foreach (var file in currentDirecotoryInfo.GetFiles())
                {
                    currentFolder.AddFile(file.Name, (int)file.Length);
                }

                foreach (var dir in subDirectories)
                {
                    currentFolder.AddFolder(dir.FullName);
                }

                foreach (var child in currentFolder.ChildFolders)
                {
                    TraverseDirectory(child);
                }
            }
            catch (UnauthorizedAccessException uae)
            {
                Console.WriteLine("Cannot access directory: {0}", uae.Message);
            }
            catch(DirectoryNotFoundException dnf)
            {
                Console.WriteLine("Directory not found: {0}", dnf.Message);
            }
        }
开发者ID:nader-dab,项目名称:CSharp-Homeworks,代码行数:31,代码来源:Program.cs

示例4: GetAllFilesAndFolders

    private static Folder GetAllFilesAndFolders(DirectoryInfo directory)
    {
        Folder currentFolder = new Folder(directory.Name);
        try
        {
            var directories = directory.GetDirectories();
            foreach (var dir in directories)
            {
                currentFolder.AddFolder(GetAllFilesAndFolders(dir));
            }
        }
        catch (UnauthorizedAccessException uae)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(uae.Message);
            Console.ForegroundColor = ConsoleColor.Gray;
        }

        foreach (var file in directory.GetFiles())
        {
            currentFolder.AddFile(new File(file.Name, file.Length));
        }

        return currentFolder;
    }
开发者ID:bahtev,项目名称:TelerikAcademy,代码行数:25,代码来源:FilesAndFoldersTotalSize.cs

示例5: Traverse

    static Folder Traverse(string root)
    {
        var folder = new Folder(root);

        foreach (string file in Directory.GetFiles(root))
            folder.Add(new File(file, new FileInfo(file).Length));

        foreach (string directory in Directory.GetDirectories(root))
            folder.AddFolder(Traverse(directory));

        return folder;
    }
开发者ID:dgrigorov,项目名称:TelerikAcademy-1,代码行数:12,代码来源:Program.cs

示例6: TraverseDFS

    // Traverse input directory using recursive DFS and reflect its structure in input folder
    private static void TraverseDFS(DirectoryInfo directory, Folder currentFolder)
    {
        FileInfo[] files = directory.GetFiles();
        List<File> fileList = new List<File>();
        foreach (var file in files)
        {
            fileList.Add(new File(file.Name, file.Length));
        }

        currentFolder.AddFiles(fileList);

        DirectoryInfo[] children = directory.GetDirectories();
        List<Folder> folderList = new List<Folder>();
        foreach (DirectoryInfo child in children)
        {
            Folder childFolder = new Folder(child.Name);
            currentFolder.AddFolder(childFolder);
            TraverseDFS(child, childFolder);
        }
    }
开发者ID:vasilkrvasilev,项目名称:DataStructuresAlgorithms,代码行数:21,代码来源:Example.cs

示例7: FillFolder

    // Adds all files and folders from 'source' to the root folder recursively
    private static Folder FillFolder(string path, Folder root)
    {
        try
        {
            var source = new DirectoryInfo(path);

            foreach (var file in source.EnumerateFiles())
            {
                root.AddFile(new File(file.Name, file.Length));
            }

            foreach (DirectoryInfo dir in source.EnumerateDirectories())
            {
                root.AddFolder(FillFolder(dir.FullName, new Folder(dir.Name)));                
            }            
        }
        catch (System.Exception)
        { 
        }

        return root;
    }
开发者ID:MarKamenov,项目名称:TelerikAcademy,代码行数:23,代码来源:Program.cs

示例8: SaveFilesAndDirectories

    private void SaveFilesAndDirectories(Folder parent)
    {
        if (parent == null)
        {
            return;
        }

        currentDirectory = new DirectoryInfo(parent.Path);

        FileInfo[] folderFiles;

        try
        {
            folderFiles = currentDirectory.GetFiles();
        }
        catch (UnauthorizedAccessException)
        {
            return;
        }

        foreach (var file in folderFiles)
        {
            parent.AddFile(new File(file.Name, file.Length));
        }

        subDirectories = currentDirectory.GetDirectories();

        Folder subFolder;

        foreach (var directory in subDirectories)
        {
            subFolder = new Folder(directory.FullName, directory.Name);

            parent.AddFolder(subFolder);

            SaveFilesAndDirectories(subFolder);
        }
    }
开发者ID:kaloyan-penkov,项目名称:SoftUni,代码行数:38,代码来源:FoldersTree.cs


注:本文中的Folder.AddFolder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。