本文整理汇总了C#中IFileSystem.CreateDirectory方法的典型用法代码示例。如果您正苦于以下问题:C# IFileSystem.CreateDirectory方法的具体用法?C# IFileSystem.CreateDirectory怎么用?C# IFileSystem.CreateDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileSystem
的用法示例。
在下文中一共展示了IFileSystem.CreateDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractFont
internal static string ExtractFont(string name, IApplicationPaths paths, IFileSystem fileSystem)
{
var filePath = Path.Combine(paths.ProgramDataPath, "fonts", name);
if (fileSystem.FileExists(filePath))
{
return filePath;
}
var namespacePath = typeof(PlayedIndicatorDrawer).Namespace + ".fonts." + name;
var tempPath = Path.Combine(paths.TempDirectory, Guid.NewGuid().ToString("N") + ".ttf");
fileSystem.CreateDirectory(Path.GetDirectoryName(tempPath));
using (var stream = typeof(PlayedIndicatorDrawer).Assembly.GetManifestResourceStream(namespacePath))
{
using (var fileStream = new FileStream(tempPath, FileMode.Create, FileAccess.Write, FileShare.Read))
{
stream.CopyTo(fileStream);
}
}
fileSystem.CreateDirectory(Path.GetDirectoryName(filePath));
try
{
fileSystem.CopyFile(tempPath, filePath, false);
}
catch (IOException)
{
}
return tempPath;
}
示例2: Setup
public void Setup()
{
theFileSystem = new FileSystem();
theDirectory = Path.GetTempPath().AppendRandomPath();
theFileSystem.CreateDirectory(theDirectory);
createFile("1.txt");
createFile("2.txt");
createFile("3.txt");
createDirectory("A");
createFile("A", "A1.txt");
createFile("A", "A2.txt");
createFile("A", "A3.txt");
createDirectory("B");
createFile("B", "B1.txt");
createDirectory("C");
createFile("C", "C1.txt");
createFile("C", "C2.txt");
theFileSystem.ForceClean(theDirectory);
}
示例3: EnsureList
/// <summary>
/// Ensures the list.
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="file">The file.</param>
/// <param name="httpClient">The HTTP client.</param>
/// <param name="fileSystem">The file system.</param>
/// <param name="semaphore">The semaphore.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
public static async Task EnsureList(string url, string file, IHttpClient httpClient, IFileSystem fileSystem, SemaphoreSlim semaphore, CancellationToken cancellationToken)
{
var fileInfo = fileSystem.GetFileInfo(file);
if (!fileInfo.Exists || (DateTime.UtcNow - fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays > 1)
{
await semaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
try
{
var temp = await httpClient.GetTempFile(new HttpRequestOptions
{
CancellationToken = cancellationToken,
Progress = new Progress<double>(),
Url = url
}).ConfigureAwait(false);
fileSystem.CreateDirectory(Path.GetDirectoryName(file));
fileSystem.CopyFile(temp, file, true);
}
finally
{
semaphore.Release();
}
}
}
示例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));
}
示例5: Setup
public void Setup()
{
theFileSystem = new FileSystem();
theDirectory = Guid.NewGuid().ToString();
theFileSystem.CreateDirectory(theDirectory);
createFile("1.txt");
createFile("2.txt");
createFile("3.txt");
createDirectory("A");
createFile("A", "A1.txt");
createFile("A", "A2.txt");
createFile("A", "A3.txt");
createDirectory("B");
createFile("B", "B1.txt");
createDirectory("C");
createFile("C", "C1.txt");
createFile("C", "C2.txt");
theFileSystem.ForceClean(theDirectory);
}
示例6: Move
public void Move(IFileSystem source, FileSystemPath sourcePath, IFileSystem destination, FileSystemPath destinationPath)
{
bool isFile;
if ((isFile = sourcePath.IsFile) != destinationPath.IsFile)
throw new ArgumentException("The specified destination-path is of a different type than the source-path.");
if (isFile)
{
using (var sourceStream = source.OpenFile(sourcePath, FileAccess.Read))
{
using (var destinationStream = destination.CreateFile(destinationPath))
{
byte[] buffer = new byte[BufferSize];
int readBytes;
while ((readBytes = sourceStream.Read(buffer, 0, buffer.Length)) > 0)
destinationStream.Write(buffer, 0, readBytes);
}
}
source.Delete(sourcePath);
}
else
{
destination.CreateDirectory(destinationPath);
foreach (var ep in source.GetEntities(sourcePath).ToArray())
{
var destinationEntityPath = ep.IsFile
? destinationPath.AppendFile(ep.EntityName)
: destinationPath.AppendDirectory(ep.EntityName);
Move(source, ep, destination, destinationEntityPath);
}
if (!sourcePath.IsRoot)
source.Delete(sourcePath);
}
}
示例7: JsonLocalizationCache
public JsonLocalizationCache(IHostingEnvironment hostingEnvironment, IFileSystem fileSystem, ILoggerFactory loggerFactory)
{
_path = hostingEnvironment.MapPath(@"json");
_fileSystem = fileSystem;
_logger = loggerFactory.CreateLogger<JsonLocalizationCache>();
_fileSystem.CreateDirectory(_path);
_fileSystem.Watch(_path, "*.json", OnChanged);
}
示例8: Execute
public void Execute(IFileSystem fileSystem)
{
fileSystem.CreateDirectory(this.fullDirectoryPath);
foreach (var fileHierarchyNode in this.children)
{
fileHierarchyNode.Execute(fileSystem);
}
}
示例9: UacCompliantPaths
public UacCompliantPaths(IFileSystem fileSystem)
{
var absoluteDataPath = Environment.ExpandEnvironmentVariables(appFolder);
fileSystem.CreateDirectory(absoluteDataPath);
Data = absoluteDataPath;
Application = AppDomain.CurrentDomain.BaseDirectory;
EnureWorkingDirectory();
}
示例10: ExecuteCreation
/// <summary>
/// Executes the creation of the folder.
/// </summary>
public void ExecuteCreation(IFileSystem fileSystem)
{
try
{
fileSystem.CreateDirectory(_associatedPath);
}
catch //(DuplicateDirectoryException)
{
// ADD SOMETHING TO LOG?
}
}
示例11: SetUp
public void SetUp()
{
theSolution = new Solution
{
Directory = "SolutionFiles"
};
theFileSystem = new FileSystem();
theFileSystem.CreateDirectory("SolutionFiles");
theSolutionFiles = new SolutionFiles(theFileSystem, new SolutionLoader());
theSolutionFiles.RootDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SolutionFiles");
theFileSystem.CreateDirectory("SolutionFiles", "src");
theFileSystem.CreateDirectory("SolutionFiles", "src", "Project1");
theFileSystem.CreateDirectory("SolutionFiles", "src", "Project2");
theFileSystem.WriteStringToFile(Path.Combine("SolutionFiles", "src", "Project1", "Project1.csproj"), "test");
theFileSystem.WriteStringToFile(Path.Combine("SolutionFiles", "src", "Project2", "Project2.csproj"), "test");
}
示例12: SetUp
public void SetUp()
{
theSolution = new Solution
{
Directory = "SolutionFiles"
};
theFileSystem = new FileSystem();
theFileSystem.CreateDirectory("SolutionFiles");
theSolutionFiles = new SolutionFiles(theFileSystem, new SolutionLoader());
theSolutionFiles.RootDir = Path.GetTempPath().AppendRandomPath();
theFileSystem.CreateDirectory("SolutionFiles", "src");
theFileSystem.CreateDirectory("SolutionFiles", "src", "Project1");
theFileSystem.CreateDirectory("SolutionFiles", "src", "Project2");
theFileSystem.WriteStringToFile(Path.Combine("SolutionFiles", "src", "Project1", "Project1.csproj"), "test");
theFileSystem.WriteStringToFile(Path.Combine("SolutionFiles", "src", "Project2", "Project2.csproj"), "test");
}
示例13: CopyFilesRecursively
public static void CopyFilesRecursively(DirectoryInfo source, string targetVirtualPath, IFileSystem fs)
{
foreach (DirectoryInfo dir in source.GetDirectories())
{
string newDirVirtualPath = Path.Combine(targetVirtualPath, dir.Name);
fs.CreateDirectory(newDirVirtualPath);
CopyFilesRecursively(dir, newDirVirtualPath, fs);
}
foreach (FileInfo file in source.GetFiles())
{
fs.WriteFile(Path.Combine(targetVirtualPath, file.Name), file.OpenRead());
}
}
示例14: Copy
public void Copy(IFileSystem source, FileSystemPath sourcePath, IFileSystem destination, FileSystemPath destinationPath)
{
var pSource = (PhysicalFileSystem)source;
var pDestination = (PhysicalFileSystem)destination;
var pSourcePath = pSource.GetPhysicalPath(sourcePath);
var pDestinationPath = pDestination.GetPhysicalPath(destinationPath);
if (sourcePath.IsFile)
System.IO.File.Copy(pSourcePath, pDestinationPath);
else
{
destination.CreateDirectory(destinationPath);
foreach(var e in source.GetEntities(sourcePath))
source.Copy(e, destination, e.IsFile ? destinationPath.AppendFile(e.EntityName) : destinationPath.AppendDirectory(e.EntityName));
}
}
示例15: 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);
}
}