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


C# IFileSystem.DirectoryExists方法代码示例

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


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

示例1: Create

        public static IDirectoryInfo Create(IFileSystem fileSystem, string path) {
            var di = Substitute.For<IDirectoryInfo>();
            di.FullName.Returns(path);
            di.Exists.Returns(true);
            di.Parent.Returns((IDirectoryInfo)null);
            di.EnumerateFileSystemInfos().Returns(new List<IFileSystemInfo>());

            fileSystem.GetDirectoryInfo(path).Returns(di);
            fileSystem.DirectoryExists(path).Returns(true);

            fileSystem.GetDirectoryInfo(path + Path.DirectorySeparatorChar).Returns(di);
            fileSystem.DirectoryExists(path + Path.DirectorySeparatorChar).Returns(true);

            return di;
        }
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:15,代码来源:DirectoryInfoStubFactory.cs

示例2: Delete

        public static IDirectoryInfo Delete(IFileSystem fileSystem, string path) {
            var di = Substitute.For<IDirectoryInfo>();
            di.FullName.Returns(path);
            di.Exists.Returns(false);
            di.Parent.Returns((IDirectoryInfo)null);
            di.EnumerateFileSystemInfos().ThrowsForAnyArgs<DirectoryNotFoundException>();

            fileSystem.GetDirectoryInfo(path).Returns(di);
            fileSystem.DirectoryExists(path).Returns(false);

            fileSystem.GetDirectoryInfo(path + Path.DirectorySeparatorChar).Returns(di);
            fileSystem.DirectoryExists(path + Path.DirectorySeparatorChar).Returns(false);

            return di;
        }
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:15,代码来源:DirectoryInfoStubFactory.cs

示例3: Deploy

        internal static void Deploy(Application application, string sourceDir, IFileSystem fileSystem, string relativePathUnderVDir = "")
        {
            if (!fileSystem.DirectoryExists(sourceDir))
            {
                throw new Exception(string.Format("Failed to deploy files to application, source directory does not exist: '{0}'.", sourceDir));
            }

            if (application.VirtualDirectories.Count <= 0)
            {
                throw new Exception(string.Format("Application '{0}' does not have a virtual directory.", application.Path));
            }

            var physicalPath = application.VirtualDirectories[0].PhysicalPath;
            if (!fileSystem.DirectoryExists(physicalPath))
            {
                fileSystem.DirectoryCreate(physicalPath);
            }

            var relativeDirectoryPath = Path.Combine(physicalPath, relativePathUnderVDir);
            if (!fileSystem.DirectoryExists(relativeDirectoryPath))
            {
                fileSystem.DirectoryCreate(relativeDirectoryPath);
            }

            fileSystem.DirectoryCopy(sourceDir, relativeDirectoryPath);
            if (string.IsNullOrEmpty(relativeDirectoryPath))
            {
                fileSystem.DirectorySetAttribute(relativeDirectoryPath, FileAttributes.Normal);
            }
        }
开发者ID:zhiliangxu,项目名称:TestEasy,代码行数:30,代码来源:ApplicationExtensions.cs

示例4: CreateNewDirectoryWithRenameAttempts

        public static string CreateNewDirectoryWithRenameAttempts(string directoryName, IFileSystem fileSystem, int maxRenameAttempts)
        {
            for (int directoryCreationAttempt = 1; directoryCreationAttempt < maxRenameAttempts; directoryCreationAttempt++)
            {
                string numberedDirectoryName;
                if (directoryCreationAttempt == 1)
                {
                    numberedDirectoryName = directoryName;
                }
                else
                {
                    string fullPath = Path.GetFullPath(directoryName);
                    string noTrailingSlash;
                    if (fullPath.EndsWith("\\"))
                    {
                        noTrailingSlash = fullPath.Substring(0, fullPath.Length - 1);
                    }
                    else
                    {
                        noTrailingSlash = fullPath;
                    }
                    numberedDirectoryName = string.Format("{0} ({1})", noTrailingSlash, directoryCreationAttempt.ToString());
                }

                if (fileSystem.DirectoryExists(numberedDirectoryName))
                {
                    continue;
                }

                fileSystem.CreateDirectory(numberedDirectoryName);
                return numberedDirectoryName;
            }

            throw new Exception(string.Format("Could not create directory: {0}. Exceeded {1} attempts.", directoryName, maxRenameAttempts));
        }
开发者ID:jzajac2,项目名称:AllYourTexts,代码行数:35,代码来源:FileCreator.cs

示例5: AddMediaPath

        /// <summary>
        /// Adds an additional mediaPath to an existing virtual folder, within either the default view or a user view
        /// </summary>
        /// <param name="fileSystem">The file system.</param>
        /// <param name="virtualFolderName">Name of the virtual folder.</param>
        /// <param name="path">The path.</param>
        /// <param name="appPaths">The app paths.</param>
        public static void AddMediaPath(IFileSystem fileSystem, string virtualFolderName, string path, IServerApplicationPaths appPaths)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException("path");
            }

			if (!fileSystem.DirectoryExists(path))
            {
                throw new DirectoryNotFoundException("The path does not exist.");
            }

            var rootFolderPath = appPaths.DefaultUserViewsPath;
            var virtualFolderPath = Path.Combine(rootFolderPath, virtualFolderName);

            var shortcutFilename = fileSystem.GetFileNameWithoutExtension(path);

            var lnk = Path.Combine(virtualFolderPath, shortcutFilename + ShortcutFileExtension);

			while (fileSystem.FileExists(lnk))
            {
                shortcutFilename += "1";
                lnk = Path.Combine(virtualFolderPath, shortcutFilename + ShortcutFileExtension);
            }

            fileSystem.CreateShortcut(lnk, path);
        }
开发者ID:rezafouladian,项目名称:Emby,代码行数:34,代码来源:LibraryHelpers.cs

示例6: Import

        public void Import(IFileSystem fs, Attachment a)
        {
            if (a.HasContents)
            {
                string path = a.Url;

                if(!fs.DirectoryExists(Path.GetDirectoryName(path)))
                {
                    fs.CreateDirectory(Path.GetDirectoryName(path));
                }

                var memoryStream = new MemoryStream(a.FileContents);
                fs.WriteFile(path, memoryStream);
            }
        }
开发者ID:GrimaceOfDespair,项目名称:n2cms,代码行数:15,代码来源:FileAttachmentAttribute.cs

示例7: RepositoryGroupManager

 /// <summary>
 /// Initializes a new instance of the <see cref="RepositoryGroupManager"/> class.  Provides nested operations over RepositoryManager instances.
 /// </summary>
 /// <param name="repository">The repository.</param>
 /// <param name="fileSystem"> </param>
 /// <example>Can be a direct path to a repository.config file</example>
 ///   
 /// <example>Can be a path to a directory, which will recursively locate all contained repository.config files</example>
 public RepositoryGroupManager(string repository, IFileSystem fileSystem)
 {
     Contract.Requires(fileSystem != null);
     this.fileSystem = fileSystem;
     
     if (fileSystem.DirectoryExists(repository))
     {
         // we're dealing with a directory
         //TODO Does this by default do a recursive???
         RepositoryManagers = new ConcurrentBag<RepositoryManager>(fileSystem.GetFiles(repository, "repositories.config", SearchOption.AllDirectories).Select(file => new RepositoryManager(file, new RepositoryEnumerator(fileSystem), fileSystem)).ToList());
     }
     else if (fileSystem.FileExists(repository) && Path.GetFileName(repository) == "repositories.config")
         RepositoryManagers = new ConcurrentBag<RepositoryManager>(new List<RepositoryManager> { new RepositoryManager(repository, new RepositoryEnumerator(fileSystem), fileSystem) });
     else
         throw new ArgumentOutOfRangeException("repository");
 }
开发者ID:modulexcite,项目名称:NuGet.Extensions,代码行数:24,代码来源:RepositoryGroupManager.cs

示例8: RemoveMediaPath

        /// <summary>
        /// Deletes a shortcut from within a virtual folder, within either the default view or a user view
        /// </summary>
        /// <param name="fileSystem">The file system.</param>
        /// <param name="virtualFolderName">Name of the virtual folder.</param>
        /// <param name="mediaPath">The media path.</param>
        /// <param name="appPaths">The app paths.</param>
        /// <exception cref="System.IO.DirectoryNotFoundException">The media folder does not exist</exception>
        public static void RemoveMediaPath(IFileSystem fileSystem, string virtualFolderName, string mediaPath, IServerApplicationPaths appPaths)
        {
            var rootFolderPath = appPaths.DefaultUserViewsPath;
            var path = Path.Combine(rootFolderPath, virtualFolderName);

			if (!fileSystem.DirectoryExists(path))
            {
                throw new DirectoryNotFoundException(string.Format("The media collection {0} does not exist", virtualFolderName));
            }
            
            var shortcut = Directory.EnumerateFiles(path, ShortcutFileSearch, SearchOption.AllDirectories).FirstOrDefault(f => fileSystem.ResolveShortcut(f).Equals(mediaPath, StringComparison.OrdinalIgnoreCase));

            if (!string.IsNullOrEmpty(shortcut))
            {
                fileSystem.DeleteFile(shortcut);
            }
        }
开发者ID:NickBolles,项目名称:Emby,代码行数:25,代码来源:LibraryHelpers.cs

示例9: Importer

        public Importer(
            IFileSystem fileSystem, 
            ITweetDataFileParser tweetDataFileParser,
            IClientProvider clientProvider, 
            IElasticConnectionSettings elasticConnectionSettings, 
            string sourceDirectory)
        {
            if (fileSystem == null) throw new ArgumentNullException("fileSystem");
            if (tweetDataFileParser == null) throw new ArgumentNullException("tweetDataFileParser");
            if (clientProvider == null) throw new ArgumentNullException("clientProvider");
            if (elasticConnectionSettings == null) throw new ArgumentNullException("elasticConnectionSettings");

            if (!fileSystem.DirectoryExists(sourceDirectory))
                throw new DirectoryNotFoundException("Source directory does not exist");

            _fileSystem = fileSystem;
            _parser = tweetDataFileParser;
            _clientProvider = clientProvider;
            _elasticConnectionSettings = elasticConnectionSettings;
            _sourceDirectory = sourceDirectory;
        }
开发者ID:AdaTheDev,项目名称:ElasticTweets,代码行数:21,代码来源:Importer.cs

示例10: DeleteFiles

        internal static void DeleteFiles(IFileSystem fileSystem, IEnumerable<IPackageFile> files, string rootDir)
        {
            // First get all directories that contain files
            var directoryLookup = files.ToLookup(p => Path.GetDirectoryName(p.Path));


            // Get all directories that this package may have added
            var directories = from grouping in directoryLookup
                              from directory in GetDirectories(grouping.Key)
                              orderby directory.Length descending
                              select directory;

            // Remove files from every directory
            foreach (var directory in directories)
            {
                var directoryFiles = directoryLookup.Contains(directory) ? directoryLookup[directory] : Enumerable.Empty<IPackageFile>();
                string dirPath = Path.Combine(rootDir, directory);

                if (!fileSystem.DirectoryExists(dirPath))
                {
                    continue;
                }

                foreach (var file in directoryFiles)
                {
                    string path = Path.Combine(rootDir, file.Path);

                    fileSystem.DeleteFileSafe(path, file.GetStream);
                }

                // If the directory is empty then delete it
                if (!fileSystem.GetFilesSafe(dirPath).Any() &&
                    !fileSystem.GetDirectoriesSafe(dirPath).Any())
                {
                    fileSystem.DeleteDirectorySafe(dirPath, recursive: false);
                }
            }
        }
开发者ID:Newtopian,项目名称:nuget,代码行数:38,代码来源:FileSystemExtensions.cs

示例11: LoadConfig

        private static Config LoadConfig(IConfigLoader configLoader, IFileSystem fileSystem)
        {
            var config = configLoader.Load<Config>("ChatLog/Config.json") ?? new Config();

            if (string.IsNullOrWhiteSpace(config.Path))
            {
                config.Path = "ChatLogs";
                Log.Info("No path specified, using 'ChatLogs'");
            }
            else
            {
                config.Path = config.Path;
            }

            try
            {
                if (fileSystem.DirectoryExists(config.Path))
                {
                    Log.Info("Path exists, skipping creation");
                }
                else
                {
                    Log.Info("Path does not exist, creating it..");
                    fileSystem.CreateDirectory(config.Path);
                }

                Log.Info($"Path is '{config.Path}'");
            }
            catch (Exception e)
            {
                Log.Error($"Error creating '{config.Path}': {e.Message}");
                Log.Error("Path not set");
            }

            return config;
        }
开发者ID:sbrydon,项目名称:Norbert,代码行数:36,代码来源:ChatLogModule.cs

示例12: DeleteTempTestDir

 private static string DeleteTempTestDir(IFileSystem fileSystem)
 {
     if (fileSystem.DirectoryExists(TestConstants.TempDirectory)) {
         fileSystem.DeleteDirectory(TestConstants.TempDirectory);
     }
     return TestConstants.TempDirectory;
 }
开发者ID:JMnITup,项目名称:PictureHandler,代码行数:7,代码来源:PictureDirectoryTests.cs

示例13: CopyNativeBinaries

        private void CopyNativeBinaries(IProjectSystem projectSystem, IFileSystem packagesFileSystem, PackageName packageName)
        {
            const string nativeBinariesFolder = "NativeBinaries";

            string nativeBinariesPath = Path.Combine(packageName.Name, nativeBinariesFolder);
            if (packagesFileSystem.DirectoryExists(nativeBinariesPath))
            {
                IEnumerable<string> nativeFiles = packagesFileSystem.GetFiles(nativeBinariesPath, "*.*", recursive: true);
                foreach (string file in nativeFiles)
                {
                    string targetPath = Path.Combine(Constants.BinDirectory, file.Substring(nativeBinariesPath.Length + 1));  // skip over NativeBinaries/ word
                    using (Stream stream = packagesFileSystem.OpenFile(file)) 
                    {
                        projectSystem.AddFile(targetPath, stream);
                    }
                }
            }
        }
开发者ID:themotleyfool,项目名称:NuGet,代码行数:18,代码来源:VsWebsiteHandler.cs

示例14: GetAssemblyReferences

        /// <summary>
        /// Gets all assembly references for a package
        /// </summary>
        private IEnumerable<IPackageAssemblyReference> GetAssemblyReferences(
            IFileSystem fileSystem, string packageId, SemanticVersion version, out string packageDirectory)
        {
            // REVIEW: do we need to search for all variations of versions here? (e.g. 1.0, 1.0.0, 1.0.0.0)
            string packageName = packageId + "." + version.ToString();
            if (fileSystem.DirectoryExists(packageName))
            {
                string libFolderPath = Path.Combine(packageName, Constants.LibDirectory);
                if (fileSystem.DirectoryExists(libFolderPath))
                {
                    packageDirectory = fileSystem.GetFullPath(packageName);
                    // TODO: SearchFilesWithinOneSubFolders seems fragile. In the event conventions in the lib directory change to allow more than one level of nesting, it would 
                    // not work. We should let VS perform a regular install instead of doing this. 
                    return Constants.AssemblyReferencesExtensions
                                    .Select(extension => "*" + extension)
                                    .SelectMany(extension => SearchFilesWithinOneSubFolders(fileSystem, libFolderPath, extension))
                                    .Select(assembly => new FileAssemblyReference(assembly.Substring(packageName.Length).Trim(Path.DirectorySeparatorChar)));
                }
            }

            packageDirectory = null;
            return Enumerable.Empty<IPackageAssemblyReference>();
        }
开发者ID:themotleyfool,项目名称:NuGet,代码行数:26,代码来源:VsWebsiteHandler.cs

示例15: EnsureVersionAssemblyInfoFile

        static bool EnsureVersionAssemblyInfoFile(Arguments arguments, IFileSystem fileSystem, string fullPath)
        {
            if (fileSystem.Exists(fullPath)) return true;

            if (!arguments.EnsureAssemblyInfo) return false;

            var assemblyInfoSource = AssemblyVersionInfoTemplates.GetAssemblyInfoTemplateFor(fullPath);
            if (!string.IsNullOrWhiteSpace(assemblyInfoSource))
            {
                var fileInfo = new FileInfo(fullPath);
                if (!fileSystem.DirectoryExists(fileInfo.Directory.FullName))
                {
                    fileSystem.CreateDirectory(fileInfo.Directory.FullName);
                }
                fileSystem.WriteAllText(fullPath, assemblyInfoSource);
                return true;
            }
            Logger.WriteWarning(string.Format("No version assembly info template available to create source file '{0}'", arguments.UpdateAssemblyInfoFileName));
            return false;
        }
开发者ID:qetza,项目名称:GitVersion,代码行数:20,代码来源:AssemblyInfoFileUpdate.cs


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