本文整理汇总了C#中System.IO.Directory类的典型用法代码示例。如果您正苦于以下问题:C# Directory类的具体用法?C# Directory怎么用?C# Directory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Directory类属于System.IO命名空间,在下文中一共展示了Directory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadDirectoryStructure
private void ReadDirectoryStructure(Directory rootDirectory)
{
List<File> files = new List<File>();
foreach (var f in rootDirectory.infos.EnumerateFiles())
{
File file = new File(f);
try
{
file.file = TagLib.File.Create(file.infos.FullName);
if (file.file is TagLib.Image.File)
file.file = null;
}
catch (TagLib.UnsupportedFormatException)
{
file.file = null;
}
files.Add(file);
}
List<Directory> directories = new List<Directory>();
foreach (var f in rootDirectory.infos.EnumerateDirectories())
directories.Add(new Directory(f));
rootDirectory.files = files;
rootDirectory.directories = directories;
foreach (var directory in directories)
{
ReadDirectoryStructure(directory);
}
}
示例2: ResolveDirectory
Directory ResolveDirectory(Directory directory, IEnumerable<string> children)
{
if (!children.Any())
return directory;
string childName = children.First();
Directory info = directory.GetDirectories()
.Where(x => string.Compare(x.Name.GetName(), childName, true) == 0)
.SingleOrDefault();
if (info != null)
{
return ResolveDirectory(info, children.Skip(1));
}
File file = directory.GetFiles()
.Where(x => string.Compare(x.Name.GetName(), childName, true) == 0)
.SingleOrDefault();
if (file == null)
throw new InvalidOperationException("Could not get directory: " + childName);
if (Path.GetExtension(file.Name.GetName()) == ".zip")
{
var zipFileDirectory = new ZipFileDirectory(file.Name.Name);
return ResolveDirectory(zipFileDirectory, children.Skip(1));
}
throw new InvalidOperationException("Could not resolve the rest of the path: " + childName);
}
示例3: Dotest
private void Dotest(int ncats, int range)
{
AtomicInteger numCats = new AtomicInteger(ncats);
Directory[] dirs = new Directory[2];
for (int i = 0; i < dirs.Length; i++)
{
dirs[i] = NewDirectory();
var tw = new DirectoryTaxonomyWriter(dirs[i]);
ThreadClass[] addThreads = new ThreadClass[4];
for (int j = 0; j < addThreads.Length; j++)
{
addThreads[j] = new ThreadAnonymousInnerClassHelper(this, range, numCats, tw);
}
foreach (ThreadClass t in addThreads)
{
t.Start();
}
foreach (ThreadClass t in addThreads)
{
t.Join();
}
tw.Dispose();
}
var tw1 = new DirectoryTaxonomyWriter(dirs[0]);
IOrdinalMap map = randomOrdinalMap();
tw1.AddTaxonomy(dirs[1], map);
tw1.Dispose();
validate(dirs[0], dirs[1], map);
IOUtils.Close(dirs);
}
示例4: AzureDirectory
/// <summary>
/// Create an AzureDirectory
/// </summary>
/// <param name="storageAccount">storage account to use</param>
/// <param name="containerName">name of container (folder in blob storage)</param>
/// <param name="cacheDirectory">local Directory object to use for local cache</param>
/// <param name="rootFolder">path of the root folder inside the container</param>
public AzureDirectory(
CloudStorageAccount storageAccount,
string containerName = null,
Directory cacheDirectory = null,
bool compressBlobs = false,
string rootFolder = null)
{
if (storageAccount == null)
throw new ArgumentNullException("storageAccount");
if (string.IsNullOrEmpty(containerName))
_containerName = "lucene";
else
_containerName = containerName.ToLower();
if (string.IsNullOrEmpty(rootFolder))
_rootFolder = string.Empty;
else
{
rootFolder = rootFolder.Trim('/');
_rootFolder = rootFolder + "/";
}
_blobClient = storageAccount.CreateCloudBlobClient();
_initCacheDirectory(cacheDirectory);
this.CompressBlobs = compressBlobs;
}
示例5: LoadFiles
public List<File> LoadFiles(Directory directory, Func<string, bool> filter, bool getDirectoryIcons = true)
{
RequestResult result = OAuthUtility.Get("https://api.dropbox.com/1/metadata/auto/", new HttpParameterCollection { { "path", directory.Path }, { "access_token", AccessToken } });
if (IsSuccess(result)) {
return null;
}
return result["contents"].Where(i => Convert.ToBoolean(i["is_dir"]) || filter(i["path"].ToString())).OrderBy(i => Path.GetFileName(i["path"].ToString())).OrderByDescending(i => Convert.ToBoolean(i["is_dir"])).Select(i => Convert.ToBoolean(i["is_dir"]) ? new Directory(directory, i["path"].ToString(), Path.GetFileName(i["path"].ToString()), GetIcon(i)) : new File(directory, i["path"].ToString(), Path.GetFileName(i["path"].ToString()), GetIcon(i))).ToList();
}
示例6: LoadFiles
public List<File> LoadFiles(Directory directory, Func<string, bool> filter, bool getDirectoryIcons = true)
{
if (string.IsNullOrEmpty(directory.Path)) {
return FileSystemHelper.GetFixedDrives().Select(d => new Directory(directory, d.Name, d.Name, FileSystemHelper.GetImage(d.Name, IconSizeType.Small, imgSize))).ToList<File>();
}
FileSystemEntryCollection collection = GetFileSystemEntries(directory.Path, IconSizeType.Small, imgSize, getDirectoryIcons);
collection.ShowExtensions = true;
return collection.Where(entry => entry is DirectoryEntry || filter(entry.Path)).Select(entry => { return entry is DirectoryEntry ? new Directory(directory, entry.Path, entry.Name, entry.Image) : new File(directory, entry.Path, entry.Name, entry.Image);}).ToList();
}
示例7: CreateDirectory
//public static void IORename(Directory current_directory, string old_name, string new_name)
//{
// if (System.IO.File.Exists(current_directory.FullPhysicalPath + new_name))
// {
// // new file name is already taken
// throw (new System.Data.DuplicateNameException("File already exists"));
// }
// else
// {
// if (System.IO.Directory.Exists(current_directory.FullPhysicalPath + old_name))
// {
// // directory
// if (current_directory.Settings.Recursive && current_directory.Settings.AllowModifySubdirectories)
// {
// System.IO.Directory.Move(current_directory.FullPhysicalPath + old_name, current_directory.FullPhysicalPath + new_name);
// }
// else
// {
// throw (new System.Security.SecurityException("Modifying directories is forbidden in configuration"));
// }
// }
// else if (System.IO.File.Exists(current_directory.FullPhysicalPath + old_name))
// {
// // file
// string ext = new_name.Contains(".")?new_name.Substring(new_name.LastIndexOf(".")+1):String.Empty;
// // validate file type
// bool valid_ext = current_directory.Settings.AllowAnyFiletypes;
// if (!valid_ext)
// {
// foreach(string ft_str in current_directory.Settings.AllowedFileTypes)
// {
// FileType ft = FileType.GetFileType(current_directory.Configuration, ft_str);
// if (ft.Extensions.Contains(ext))
// {
// valid_ext = true;
// break;
// }
// }
// }
// if (valid_ext)
// {
// // extension is valid, proceed
// System.IO.File.Move(current_directory.FullPhysicalPath + old_name, current_directory.FullPhysicalPath + new_name);
// }
// else
// {
// throw (new ArgumentException("New file extension is not valid."));
// }
// }
// else
// {
// // not found
// throw (new FileNotFoundException("File or directory " + (current_directory.FullPhysicalPath + old_name) + " not found"));
// }
// }
//}
public static void CreateDirectory(Directory current_directory, string dirname)
{
FtpWebRequest reqFTP = _MakeFtpWebRequest(current_directory, dirname);
// Specify the command to be executed.
reqFTP.Method = WebRequestMethods.Ftp.MakeDirectory;
// Execute the command.
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
response.Close();
}
示例8: ZipDirectory
/// <summary>
/// Adds a directory to a specific ZipStream
/// </summary>
/// <param name="RootDirectory">the root directory</param>
/// <param name="CurrentDirectory">the directory to push</param>
/// <param name="zStream">stream to write to</param>
/// <remarks>
/// do not call this method directly, this method is designed be called in a recursive manor.
/// </remarks>
private void ZipDirectory(Directory RootDirectory, Directory CurrentDirectory, ZipOutputStream zStream)
{
foreach (var file in CurrentDirectory.Files)
{
ZipEntry fileEntry = new ZipEntry(file.FilePath);
zStream.PutNextEntry(fileEntry);
zStream.Write(file.FileContents, 0, file.FileContents.Length);
}
foreach (var subDirectory in CurrentDirectory.Directories)
ZipDirectory(RootDirectory, subDirectory, zStream);
}
示例9: CompressDirectory
/// <summary>
/// Compresses a directory using Zip compression into a specified directory
/// </summary>
/// <param name="ArchiveOutputLocation">the output directory path (including file name)</param>
/// <param name="ArchiveDirectory">the Directory object to be compressed</param>
/// <remarks>
/// is recursive
/// </remarks>
public void CompressDirectory(string ArchiveOutputLocation, Directory ArchiveDirectory)
{
using (ZipOutputStream zStream = new ZipOutputStream(System.IO.File.Create(ArchiveOutputLocation)))
{
foreach (var file in ArchiveDirectory.Files)
{
ZipEntry fileEntry = new ZipEntry(file.FullPath);
zStream.PutNextEntry(fileEntry);
zStream.Write(file.FileContents, 0, file.FileContents.Length);
}
foreach (var directory in ArchiveDirectory.Directories)
ZipDirectory(ArchiveDirectory, directory, zStream);
zStream.Finish();
zStream.Close();
}
}
示例10: BeforeClass
public static void BeforeClass()
{
TestDoc = new Document();
FieldInfos = new FieldInfos.Builder();
DocHelper.SetupDoc(TestDoc);
foreach (IndexableField field in TestDoc)
{
FieldInfos.AddOrUpdate(field.Name(), field.FieldType());
}
Dir = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetMergePolicy(NewLogMergePolicy());
conf.MergePolicy.NoCFSRatio = 0.0;
IndexWriter writer = new IndexWriter(Dir, conf);
writer.AddDocument(TestDoc);
writer.Dispose();
FaultyIndexInput.DoFail = false;
}
示例11: AddDocs
internal virtual void AddDocs(Random random, Directory dir, int ndocs, string field, string val, int maxTF, float percentDocs)
{
Analyzer analyzer = new AnalyzerAnonymousInnerClassHelper(this, random, val, maxTF, percentDocs);
Document doc = new Document();
doc.Add(NewStringField(field, val, Field.Store.NO));
IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, analyzer).SetOpenMode(OpenMode_e.CREATE).SetMaxBufferedDocs(100).SetMergePolicy(NewLogMergePolicy(100)));
for (int i = 0; i < ndocs; i++)
{
writer.AddDocument(doc);
}
writer.ForceMerge(1);
writer.Dispose();
}
示例12: CreateDirectory_Content_from_Readable_files_gets_written_to_disk
public void CreateDirectory_Content_from_Readable_files_gets_written_to_disk()
{
var rootName = Path.GetRandomFileName();
const string fileContent = "Hello World!";
var directory = new Directory(rootName)
{
root => new TestReadableFile(root, s_File1, fileContent)
};
m_Instance.CreateDirectory(directory, Path.GetTempPath());
var expectedFilePath = Path.Combine(Path.GetTempPath(), rootName, s_File1);
Assert.True(NativeFile.Exists(expectedFilePath));
Assert.Equal(fileContent, NativeFile.ReadAllText(expectedFilePath));
}
示例13: CreateTemporaryDirectory_created_directory_gets_deleted_on_dispose
public void CreateTemporaryDirectory_created_directory_gets_deleted_on_dispose()
{
// create temporary directory
var dirName = Path.GetRandomFileName();
var directory = new Directory(dirName);
var createdDir = m_Instance.CreateTemporaryDirectory(directory);
// assert that the directory was really created
Assert.True(NativeDirectory.Exists(Path.Combine(Path.GetTempPath(), dirName)));
// dispose the temporary directory
createdDir.Dispose();
// directory has to be gone now
Assert.False(NativeDirectory.Exists(Path.Combine(Path.GetTempPath(), dirName)));
}
示例14: AzureDirectory
/// <summary>
/// Create an AzureDirectory
/// </summary>
/// <param name="storageAccount">storage account to use</param>
/// <param name="catalog">name of catalog (folder in blob storage)</param>
/// <param name="cacheDirectory">local Directory object to use for local cache</param>
public AzureDirectory(
CloudStorageAccount storageAccount,
string catalog = null,
Directory cacheDirectory = null,
bool compressBlobs = false)
{
if (storageAccount == null)
throw new ArgumentNullException("storageAccount");
if (string.IsNullOrEmpty(catalog))
_catalog = "lucene";
else
_catalog = catalog.ToLower();
_blobClient = storageAccount.CreateCloudBlobClient();
_initCacheDirectory(cacheDirectory);
this.CompressBlobs = compressBlobs;
}
示例15: SetUp
public override void SetUp()
{
base.SetUp();
Directory = NewDirectory();
IndexWriter writer = new IndexWriter(Directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetMergePolicy(NewLogMergePolicy()));
//writer.setNoCFSRatio(0.0);
//writer.infoStream = System.out;
FieldType customType = new FieldType(TextField.TYPE_STORED);
customType.Tokenized = false;
customType.StoreTermVectors = true;
for (int i = 0; i < NumDocs; i++)
{
Documents.Document doc = new Documents.Document();
Field fld = NewField("field", English.IntToEnglish(i), customType);
doc.Add(fld);
writer.AddDocument(doc);
}
writer.Dispose();
}