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


C# DirectoryInfoBase.Create方法代码示例

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


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

示例1: Organise

        public void Organise(IMedia media, DirectoryInfoBase outputDirectory, OrganiserConversionOptions conversionOption, bool strictSeason)
        {
            // Create working directory.
            WorkingDirectory = _fileSystem.DirectoryInfo.FromDirectoryName(_fileSystem.Path.Combine(_fileSystem.Path.GetTempPath(), "WorkingArea"));

            // Create working directory if it does not exist.
            if(!WorkingDirectory.Exists)
            {
                WorkingDirectory.Create();
            }

            // Copy to working area.
            CopyMediaToWorkingArea(media);

            // Convert if required.
            if(conversionOption == OrganiserConversionOptions.Force)
            {
                Logger.Log("Organiser").StdOut.WriteLine("Conversion set to \"force\". Will convert. {0}", media.MediaFile.FullName);
                ConvertMedia(media);
            }
            else if(media.RequiresConversion)
            {
                if(conversionOption == OrganiserConversionOptions.Skip)
                {
                    Logger.Log("Organiser").StdOut.WriteLine("Media requires conversion. Conversion set to \"skip\", skipping conversion. {0}", media.MediaFile.FullName);
                }
                else
                {
                    Logger.Log("Organiser").StdOut.WriteLine("Media requires conversion. Will convert. {0}", media.MediaFile.FullName);
                    ConvertMedia(media);
                }
            }

            // Extract media details exhaustivly.
            ExtractExhaustiveMediaDetails(media, strictSeason);

            // Save media meta data.
            var saveResponse = SaveMediaMetaData(media);
            if(!saveResponse)
            {
                if(conversionOption == OrganiserConversionOptions.Skip)
                {
                    Logger.Log("Organiser").StdOut.WriteLine("Unable to save metadata. Conversion set to \"skip\", skipping conversion. {0}", media.MediaFile.FullName);
                }
                else
                {
                    Logger.Log("Organiser").StdOut.WriteLine("Unable to save metadata. Will convert. {0}", media.MediaFile.FullName);
                    ConvertMedia(media);
                    SaveMediaMetaData(media);
                }
            }

            // Rename media.
            RenameMediaToCleanFileName(media);

            // If output directory not provided, delete file. Otherwise move to output directory.
            MoveMediaToOutputDirectory(media, outputDirectory);
        }
开发者ID:dipeshc,项目名称:MediaOrganiser,代码行数:58,代码来源:Organiser.cs

示例2: TVDBTVShowMetadataSource

        public TVDBTVShowMetadataSource(IFileSystem fileSystem, string apiKey)
        {
            // Set fileSystem.
            _fileSystem = fileSystem;

            // Make cache directory.
            var assemblyName = Assembly.GetExecutingAssembly().GetName().Name;
            _tvdbCacheDirectory = _fileSystem.DirectoryInfo.FromDirectoryName(_fileSystem.Path.Combine(_fileSystem.Path.GetTempPath(), assemblyName + _fileSystem.Path.DirectorySeparatorChar +"TVDBCache"));
            if(!_tvdbCacheDirectory.Exists)
            {
                _tvdbCacheDirectory.Create();
            }

            // Initalise handler with cache.
            _tvdbHandler = new TvdbHandler(new XmlCacheProvider(_tvdbCacheDirectory.FullName), apiKey);
            if(!_tvdbHandler.IsCacheInitialised)
            {
                _tvdbHandler.InitCache();
            }
        }
开发者ID:dipeshc,项目名称:MediaPod,代码行数:20,代码来源:TVDBTVShowMetadataSource.cs

示例3: Copy

        internal static void Copy(string sourcePath,
                                  string destinationPath,
                                  DirectoryInfoBase sourceDirectory,
                                  DirectoryInfoBase destinationDirectory,
                                  Func<string, DirectoryInfoBase> createDirectoryInfo,
                                  bool skipScmFolder)
        {
            // Skip hidden directories and directories that begin with .
            if (skipScmFolder && IsSourceControlFolder(sourceDirectory))
            {
                return;
            }

            if (!destinationDirectory.Exists)
            {
                destinationDirectory.Create();
            }

            foreach (var sourceFile in sourceDirectory.GetFiles())
            {
                string path = GetDestinationPath(sourcePath, destinationPath, sourceFile);

                sourceFile.CopyTo(path, overwrite: true);
            }

            var destDirectoryLookup = GetDirectories(destinationDirectory);
            foreach (var sourceSubDirectory in sourceDirectory.GetDirectories())
            {
                DirectoryInfoBase targetSubDirectory;
                if (!destDirectoryLookup.TryGetValue(sourceSubDirectory.Name, out targetSubDirectory))
                {
                    string path = GetDestinationPath(sourcePath, destinationPath, sourceSubDirectory);
                    targetSubDirectory = createDirectoryInfo(path);
                }

                Copy(sourcePath, destinationPath, sourceSubDirectory, targetSubDirectory, createDirectoryInfo, skipScmFolder);
            }
        }
开发者ID:lookworld,项目名称:kudu,代码行数:38,代码来源:FileSystemHelpers.cs

示例4: CreateDirectoryPutResponse

        protected override Task<HttpResponseMessage> CreateDirectoryPutResponse(DirectoryInfoBase info, string localFilePath)
        {
            if (info != null && info.Exists)
            {
                // Return a conflict result
                return base.CreateDirectoryPutResponse(info, localFilePath);
            }

            try
            {
                info.Create();
            }
            catch (IOException ex)
            {
                Tracer.TraceError(ex);
                HttpResponseMessage conflictDirectoryResponse = Request.CreateErrorResponse(
                    HttpStatusCode.Conflict, Resources.VfsControllerBase_CannotDeleteDirectory);
                return Task.FromResult(conflictDirectoryResponse);
            }

            // Return 201 Created response
            HttpResponseMessage successFileResponse = Request.CreateResponse(HttpStatusCode.Created);
            return Task.FromResult(successFileResponse);
        }
开发者ID:NorimaConsulting,项目名称:kudu,代码行数:24,代码来源:VfsController.cs

示例5: SmartCopy

        internal static void SmartCopy(string sourcePath,
                                       string destinationPath,
                                       Func<string, bool> existsInPrevious,
                                       DirectoryInfoBase sourceDirectory,
                                       DirectoryInfoBase destinationDirectory,
                                       Func<string, DirectoryInfoBase> createDirectoryInfo)
        {
            // Skip source control folder
            if (FileSystemHelpers.IsSourceControlFolder(sourceDirectory))
            {
                return;
            }

            if (!destinationDirectory.Exists)
            {
                destinationDirectory.Create();
            }

            // var previousFilesLookup = GetFiles(previousDirectory);
            var destFilesLookup = FileSystemHelpers.GetFiles(destinationDirectory);
            var sourceFilesLookup = FileSystemHelpers.GetFiles(sourceDirectory);

            foreach (var destFile in destFilesLookup.Values)
            {
                // If the file doesn't exist in the source, only delete if:
                // 1. We have no previous directory
                // 2. We have a previous directory and the file exists there

                // Trim the start path
                string previousPath = destFile.FullName.Substring(destinationPath.Length).TrimStart('\\');
                if (!sourceFilesLookup.ContainsKey(destFile.Name) &&
                    ((existsInPrevious == null) ||
                    (existsInPrevious != null &&
                    existsInPrevious(previousPath))))
                {
                    destFile.Delete();
                }
            }

            foreach (var sourceFile in sourceFilesLookup.Values)
            {
                // Skip the .deployment file
                if (sourceFile.Name.Equals(DeploymentConfiguration.DeployConfigFile, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                // if the file exists in the destination then only copy it again if it's
                // last write time is different than the same file in the source (only if it changed)
                FileInfoBase targetFile;
                if (destFilesLookup.TryGetValue(sourceFile.Name, out targetFile) &&
                    sourceFile.LastWriteTimeUtc == targetFile.LastWriteTimeUtc)
                {
                    continue;
                }

                // Otherwise, copy the file
                string path = FileSystemHelpers.GetDestinationPath(sourcePath, destinationPath, sourceFile);

                OperationManager.Attempt(() => sourceFile.CopyTo(path, overwrite: true));
            }

            var sourceDirectoryLookup = FileSystemHelpers.GetDirectores(sourceDirectory);
            var destDirectoryLookup = FileSystemHelpers.GetDirectores(destinationDirectory);

            foreach (var destSubDirectory in destDirectoryLookup.Values)
            {
                // If the directory doesn't exist in the source, only delete if:
                // 1. We have no previous directory
                // 2. We have a previous directory and the file exists there

                string previousPath = destSubDirectory.FullName.Substring(destinationPath.Length).TrimStart('\\');
                if (!sourceDirectoryLookup.ContainsKey(destSubDirectory.Name) &&
                    ((existsInPrevious == null) ||
                    (existsInPrevious != null &&
                    existsInPrevious(previousPath))))
                {
                    destSubDirectory.Delete(recursive: true);
                }
            }

            foreach (var sourceSubDirectory in sourceDirectoryLookup.Values)
            {
                DirectoryInfoBase targetSubDirectory;
                if (!destDirectoryLookup.TryGetValue(sourceSubDirectory.Name, out targetSubDirectory))
                {
                    string path = FileSystemHelpers.GetDestinationPath(sourcePath, destinationPath, sourceSubDirectory);
                    targetSubDirectory = createDirectoryInfo(path);
                }

                // Sync all sub directories
                SmartCopy(sourcePath, destinationPath, existsInPrevious, sourceSubDirectory, targetSubDirectory, createDirectoryInfo);
            }
        }
开发者ID:cburgdorf,项目名称:kudu,代码行数:94,代码来源:DeploymentHelper.cs

示例6: SmartCopy

        private void SmartCopy(string sourcePath,
                               string destinationPath,
                               string targetSubFolder,
                               DirectoryInfoBase sourceDirectory,
                               DirectoryInfoBase destinationDirectory)
        {
            if (IgnorePath(sourceDirectory))
            {
                return;
            }

            // No need to copy a directory to itself
            if (destinationPath == sourceDirectory.FullName)
            {
                return;
            }

            if (!destinationDirectory.Exists)
            {
                destinationDirectory.Create();
                if (_options.CopyMetaData)
                {
                    destinationDirectory.Attributes = sourceDirectory.Attributes;
                }
            }

            var destFilesLookup = FileSystemHelpers.GetFiles(destinationDirectory);
            var sourceFilesLookup = FileSystemHelpers.GetFiles(sourceDirectory);

            foreach (var destFile in destFilesLookup.Values)
            {
                if (IgnorePath(destFile))
                {
                    continue;
                }

                // If the file doesn't exist in the source, only delete if:
                // 1. We have no previous directory
                // 2. We have a previous directory and the file exists there

                // Trim the start destinationFilePath
                string previousPath = FileSystemHelpers.GetRelativePath(destinationPath, destFile.FullName);
                if (!sourceFilesLookup.ContainsKey(destFile.Name) && DoesPathExistsInManifest(previousPath, targetSubFolder))
                {
                    _logger.Log("Deleting file: '{0}'", previousPath);
                    OperationManager.Attempt(() => SmartDeleteFile(destFile));
                }
            }

            foreach (var sourceFile in sourceFilesLookup.Values)
            {
                if (IgnorePath(sourceFile))
                {
                    continue;
                }

                _nextManifest.AddPath(sourcePath, sourceFile.FullName, targetSubFolder);

                // if the file exists in the destination then only copy it again if it's
                // last write time is different than the same file in the source (only if it changed)
                FileInfoBase targetFile;
                if (destFilesLookup.TryGetValue(sourceFile.Name, out targetFile) &&
                    sourceFile.LastWriteTimeUtc == targetFile.LastWriteTimeUtc)
                {
                    continue;
                }

                // Otherwise, copy the file
                string path = FileSystemHelpers.GetDestinationPath(sourcePath, destinationPath, sourceFile);

                var details = FileSystemHelpers.GetRelativePath(sourcePath, sourceFile.FullName) + (_options.CopyMetaData ? " " + ShorthandAttributes(sourceFile) : String.Empty);
                _logger.Log("Copying file: '{0}'", details);
                OperationManager.Attempt(() => SmartCopyFile(sourceFile, path));
            }

            var sourceDirectoryLookup = FileSystemHelpers.GetDirectories(sourceDirectory);
            var destDirectoryLookup = FileSystemHelpers.GetDirectories(destinationDirectory);

            foreach (var destSubDirectory in destDirectoryLookup.Values)
            {
                // If the directory doesn't exist in the source, only delete if:
                // 1. We have no previous directory
                // 2. We have a previous directory and the file exists there

                if (!sourceDirectoryLookup.ContainsKey(destSubDirectory.Name))
                {
                    SmartDirectoryDelete(destSubDirectory, destinationPath, targetSubFolder);
                }
            }

            foreach (var sourceSubDirectory in sourceDirectoryLookup.Values)
            {
                DirectoryInfoBase targetSubDirectory;
                if (!destDirectoryLookup.TryGetValue(sourceSubDirectory.Name, out targetSubDirectory))
                {
                    string path = FileSystemHelpers.GetDestinationPath(sourcePath, destinationPath, sourceSubDirectory);
                    targetSubDirectory = CreateDirectoryInfo(path);
                }

                _nextManifest.AddPath(sourcePath, sourceSubDirectory.FullName, targetSubFolder);
//.........这里部分代码省略.........
开发者ID:kostrse,项目名称:KuduSync.NET,代码行数:101,代码来源:KuduSync.cs

示例7: SmartCopy

        private void SmartCopy(string sourcePath,
                               string destinationPath,
                               DirectoryInfoBase sourceDirectory,
                               DirectoryInfoBase destinationDirectory)
        {
            // Skip source control folder
            if (IgnorePath(sourceDirectory))
            {
                return;
            }

            if (!destinationDirectory.Exists)
            {
                destinationDirectory.Create();
            }

            var destFilesLookup = FileSystemHelpers.GetFiles(destinationDirectory);
            var sourceFilesLookup = FileSystemHelpers.GetFiles(sourceDirectory);

            foreach (var destFile in destFilesLookup.Values)
            {
                // If the file doesn't exist in the source, only delete if:
                // 1. We have no previous directory
                // 2. We have a previous directory and the file exists there

                // Trim the start path
                string previousPath = destFile.FullName.Substring(destinationPath.Length).TrimStart('\\');
                if (!sourceFilesLookup.ContainsKey(destFile.Name) && DoesPathExistsInManifest(previousPath))
                {
                    Logger.Log("Deleting file: {0}", destFile.FullName);
                    destFile.Delete();
                }
            }

            foreach (var sourceFile in sourceFilesLookup.Values)
            {
                // Skip the .deployment file
                if (IgnorePath(sourceFile))
                {
                    continue;
                }

                _nextManifest.AddPath(sourcePath, sourceFile.FullName);

                // if the file exists in the destination then only copy it again if it's
                // last write time is different than the same file in the source (only if it changed)
                FileInfoBase targetFile;
                if (destFilesLookup.TryGetValue(sourceFile.Name, out targetFile) &&
                    sourceFile.LastWriteTimeUtc == targetFile.LastWriteTimeUtc)
                {
                    continue;
                }

                // Otherwise, copy the file
                string path = FileSystemHelpers.GetDestinationPath(sourcePath, destinationPath, sourceFile);

                Logger.Log("Copying file from: {0} to: {1}", sourceFile.FullName, path);
                OperationManager.Attempt(() => sourceFile.CopyTo(path, overwrite: true));
            }

            var sourceDirectoryLookup = FileSystemHelpers.GetDirectories(sourceDirectory);
            var destDirectoryLookup = FileSystemHelpers.GetDirectories(destinationDirectory);

            foreach (var destSubDirectory in destDirectoryLookup.Values)
            {
                // If the directory doesn't exist in the source, only delete if:
                // 1. We have no previous directory
                // 2. We have a previous directory and the file exists there

                string previousPath = destSubDirectory.FullName.Substring(destinationPath.Length).TrimStart('\\');
                if (!sourceDirectoryLookup.ContainsKey(destSubDirectory.Name) && DoesPathExistsInManifest(previousPath))
                {
                    Logger.Log("Deleting directory: {0}", destSubDirectory.FullName);
                    destSubDirectory.Delete(recursive: true);
                }
            }

            foreach (var sourceSubDirectory in sourceDirectoryLookup.Values)
            {
                DirectoryInfoBase targetSubDirectory;
                if (!destDirectoryLookup.TryGetValue(sourceSubDirectory.Name, out targetSubDirectory))
                {
                    string path = FileSystemHelpers.GetDestinationPath(sourcePath, destinationPath, sourceSubDirectory);
                    targetSubDirectory = CreateDirectoryInfo(path);
                }

                _nextManifest.AddPath(sourcePath, sourceSubDirectory.FullName);

                // Sync all sub directories
                SmartCopy(sourcePath, destinationPath, sourceSubDirectory, targetSubDirectory);
            }
        }
开发者ID:amitapl,项目名称:KuduSync.NET,代码行数:92,代码来源:KuduSync.cs

示例8: SmartCopy

        internal static void SmartCopy(string sourcePath,
                                       string destinationPath,
                                       DirectoryInfoBase previousDirectory,
                                       DirectoryInfoBase sourceDirectory,
                                       DirectoryInfoBase destinationDirectory,
                                       Func<string, DirectoryInfoBase> createDirectoryInfo,
                                       bool skipOldFiles)
        {
            // Skip hidden directories and directories that begin with .
            if (sourceDirectory.Attributes.HasFlag(FileAttributes.Hidden) ||
                sourceDirectory.Name.StartsWith(".")) {
                return;
            }

            if (!destinationDirectory.Exists) {
                destinationDirectory.Create();
            }

            var previousFilesLookup = GetFiles(previousDirectory);
            var destFilesLookup = GetFiles(destinationDirectory);
            var sourceFilesLookup = GetFiles(sourceDirectory);

            foreach (var destFile in destFilesLookup.Values) {
                // If the file doesn't exist in the source, only delete if:
                // 1. We have no previous directory
                // 2. We have a previous directory and the file exists there
                if (!sourceFilesLookup.ContainsKey(destFile.Name) &&
                    ((previousFilesLookup == null) ||
                    (previousFilesLookup != null &&
                    previousFilesLookup.ContainsKey(destFile.Name)))) {
                    destFile.Delete();
                }
            }

            foreach (var sourceFile in sourceFilesLookup.Values) {
                // Skip files that start with .
                if (sourceFile.Name.StartsWith(".")) {
                    continue;
                }

                // If a file exists in the destination then only copy it again if it's
                // last write time is greater than the same file in the source (only if it changed)
                FileInfoBase targetFile;
                if (skipOldFiles &&
                    destFilesLookup.TryGetValue(sourceFile.Name, out targetFile) &&
                    sourceFile.LastWriteTimeUtc <= targetFile.LastWriteTimeUtc) {
                    continue;
                }

                // Otherwise, copy the file
                string path = GetDestinationPath(sourcePath, destinationPath, sourceFile);

                sourceFile.CopyTo(path, overwrite: true);
            }

            var previousDirectoryLookup = GetDirectores(previousDirectory);
            var sourceDirectoryLookup = GetDirectores(sourceDirectory);
            var destDirectoryLookup = GetDirectores(destinationDirectory);

            foreach (var destSubDirectory in destDirectoryLookup.Values) {
                // If the directory doesn't exist in the source, only delete if:
                // 1. We have no previous directory
                // 2. We have a previous directory and the file exists there
                if (!sourceDirectoryLookup.ContainsKey(destSubDirectory.Name) &&
                    ((previousDirectoryLookup == null) ||
                    (previousDirectoryLookup != null &&
                    previousDirectoryLookup.ContainsKey(destSubDirectory.Name)))) {
                    destSubDirectory.Delete(recursive: true);
                }
            }

            foreach (var sourceSubDirectory in sourceDirectoryLookup.Values) {
                DirectoryInfoBase targetSubDirectory;
                if (!destDirectoryLookup.TryGetValue(sourceSubDirectory.Name, out targetSubDirectory)) {
                    string path = GetDestinationPath(sourcePath, destinationPath, sourceSubDirectory);
                    targetSubDirectory = createDirectoryInfo(path);
                }

                DirectoryInfoBase previousSubDirectory = null;
                if (previousDirectoryLookup != null) {
                    // Try to get the sub folder from the previous directory
                    previousDirectoryLookup.TryGetValue(sourceSubDirectory.Name, out previousSubDirectory);
                }

                // Sync all sub directories
                SmartCopy(sourcePath, destinationPath, previousSubDirectory, sourceSubDirectory, targetSubDirectory, createDirectoryInfo, skipOldFiles);
            }
        }
开发者ID:RaleighHokie,项目名称:kudu,代码行数:88,代码来源:FileSystemHelpers.cs


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