本文整理汇总了C#中System.IO.DirectoryInfo.Refresh方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.Refresh方法的具体用法?C# DirectoryInfo.Refresh怎么用?C# DirectoryInfo.Refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.DirectoryInfo
的用法示例。
在下文中一共展示了DirectoryInfo.Refresh方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SafeDelete
public void SafeDelete()
{
var dir = new DirectoryInfo("abc");
dir.SafeDelete(true);
dir.Refresh();
Assert.That(dir.SafeDelete(true), Is.False);
Directory.CreateDirectory(dir.GetDirectory("test2").FullName);
dir.Refresh();
Assert.That(dir.SafeDelete(true), Is.True);
dir.Refresh();
Assert.That(dir.Exists, Is.False);
}
示例2: AreaState
/// <summary>
/// Initializes an area from a directory.
/// </summary>
public AreaState(ISystemContext context, DirectoryInfo directoryInfo) : base(null)
{
directoryInfo.Refresh();
string name = directoryInfo.Name;
// need to read the correct casing from the file system.
if (directoryInfo.Exists)
{
DirectoryInfo[] directories = directoryInfo.Parent.GetDirectories(name);
if (directories != null && directories.Length > 0)
{
name = directories[0].Name;
}
}
// get the system to use.
FileSystemMonitor system = context.SystemHandle as FileSystemMonitor;
if (system != null)
{
this.NodeId = system.CreateNodeIdFromDirectoryPath(ObjectTypes.AreaType, directoryInfo.FullName);
this.BrowseName = new QualifiedName(name, system.NamespaceIndex);
this.OnValidate = system.ValidateArea;
}
this.DisplayName = new LocalizedText(name);
this.EventNotifier = EventNotifiers.None;
this.TypeDefinitionId = GetDefaultTypeDefinitionId(context.NamespaceUris);
}
示例3: LoadStore
/// <summary>
/// Ensures that the data has been loaded in the Lucene index
///
/// SIDE EFFECT
/// This method sets property _searcher
/// </summary>
/// <param name="absoluteLucenePath">
/// Absolute path of the directory where the Lucene files get stored.
/// </param>
/// <param name="onlyIfNotExists">
/// If true, the index will only be created if there is no index at all (that is, no Lucene directory).
/// If false, this will always create a new index.
/// </param>
/// <param name="loadLuceneIndex">
/// Actually loads data into the Lucene index
/// </param>
protected void LoadStore(string absoluteLucenePath, bool onlyIfNotExists, Action<SimpleFSDirectory> loadLuceneIndex)
{
var luceneDir = new DirectoryInfo(absoluteLucenePath);
bool luceneDirExists = luceneDir.Exists;
if (!luceneDirExists)
{
luceneDir.Create();
luceneDir.Refresh();
}
var directory = new SimpleFSDirectory(luceneDir);
if (onlyIfNotExists && luceneDirExists)
{
// Make sure to always create a searcher.
// There must actually be a valid Lucene index in the directory, otherwise this will throw an exception.
_searcher = new IndexSearcher(directory, true);
return;
}
loadLuceneIndex(directory);
// Now that the index has been updated, need to open a new searcher.
// Existing searcher will still be reading the previous index.
_searcher = new IndexSearcher(directory, true);
}
示例4: copyRemoteDirectoryLocal
public void copyRemoteDirectoryLocal()
{
var info = util.GetUsernameAndPassword();
using (var s = new SSHConnection(info.Item1, info.Item2))
{
// Create a "complex" directory structure on the remote machine
s
.ExecuteCommand("mkdir -p /tmp/usergwatts/data")
.ExecuteCommand("mkdir -p /tmp/usergwatts/data/d1")
.ExecuteCommand("mkdir -p /tmp/usergwatts/data/d2")
.ExecuteCommand("echo hi1 > /tmp/usergwatts/data/f1")
.ExecuteCommand("echo hi2 > /tmp/usergwatts/data/d1/f2")
.ExecuteCommand("echo hi3 > /tmp/usergwatts/data/d2/f3")
.ExecuteCommand("echo hi4 > /tmp/usergwatts/data/d2/f4");
// Remove everything local
var d = new DirectoryInfo("./data");
if (d.Exists)
{
d.Delete(true);
d.Refresh();
}
d.Create();
// Do the copy
s.CopyRemoteDirectoryLocally("/tmp/usergwatts/data", d);
Assert.IsTrue(File.Exists(Path.Combine(d.FullName, "f1")));
Assert.IsTrue(File.Exists(Path.Combine(d.FullName, "d1", "f2")));
Assert.IsTrue(File.Exists(Path.Combine(d.FullName, "d2", "f3")));
Assert.IsTrue(File.Exists(Path.Combine(d.FullName, "d2", "f4")));
}
}
示例5: AttemptToDownloadBadDS
public void AttemptToDownloadBadDS()
{
// Seen in wild: try to download a bad dataset, and it creates a directory
// anyway. Ops!
var dsinfo = MakeDSInfo("ds1.1.1");
var d = new DirectoryInfo("AttemptToDownloadBadDS");
if (d.Exists)
{
d.Delete(true);
}
var ld = new LinuxMirrorDownloaderPretend(d, "forkitover");
var gf = new GRIDFetchToLinuxVisibleOnWindows(d, ld, "/bogus/files/store");
try {
var r = gf.GetDS(dsinfo);
} catch (ArgumentException)
{
// Expecting it to throw here - no dataset should exist by that name!
}
// Did a local directory get created?
d.Refresh();
Assert.IsFalse(d.Exists);
}
示例6: Create
/// <summary>
/// Creates a file from a list of strings; each string is placed on a line in the file.
/// </summary>
/// <param name="TempFileName">Name of response file</param>
/// <param name="Lines">List of lines to write to the response file</param>
public static string Create(string TempFileName, List<string> Lines)
{
FileInfo TempFileInfo = new FileInfo( TempFileName );
DirectoryInfo TempFolderInfo = new DirectoryInfo( TempFileInfo.DirectoryName );
// Delete the existing file if it exists
if( TempFileInfo.Exists )
{
TempFileInfo.IsReadOnly = false;
TempFileInfo.Delete();
TempFileInfo.Refresh();
}
// Create the folder if it doesn't exist
if( !TempFolderInfo.Exists )
{
// Create the
TempFolderInfo.Create();
TempFolderInfo.Refresh();
}
using( FileStream Writer = TempFileInfo.OpenWrite() )
{
using( StreamWriter TextWriter = new StreamWriter( Writer ) )
{
Lines.ForEach( x => TextWriter.WriteLine( x ) );
}
}
return TempFileName;
}
示例7: TestReadWriteFileDirectory
public void TestReadWriteFileDirectory()
{
DirectoryInfo dir = new DirectoryInfo(@"c:\_junk\rwtesting");
if (dir.Exists)
dir.Delete(true);
dir.Refresh();
ReaderWriter rw = new ReaderWriter();
Assert.IsFalse(rw.Exists(dir));
rw.CreateDirectory(dir);
Assert.IsTrue(rw.Exists(dir));
string blah = "blah";
string fileName = "blah.txt";
FileInfo file = new FileInfo(Path.Combine(dir.FullName, fileName));
Assert.IsFalse(rw.Exists(file));
rw.WriteFile(file, blah.Encode());
Assert.IsTrue(rw.Exists(file));
byte[] buffer = rw.ReadFile(file);
string result = buffer.Decode();
Assert.AreEqual(blah, result);
rw.Delete(file);
Assert.IsFalse(file.Exists);
rw.Delete(dir);
Assert.IsFalse(dir.Exists);
}
示例8: Main
static void Main(string[] args)
{
//validate input arguements
if(args.Length != 1)
PrintUsageAndExit(FileErrors.FILE_DOES_NOT_EXIST);
else
inputFilename = args[0];
//validate file type and that it exists
FileInfo fInfo = new FileInfo(inputFilename);
if(!fInfo.Exists)
PrintUsageAndExit(FileErrors.FILE_DOES_NOT_EXIST);
else if(!fInfo.Extension.Equals(".go"))
PrintUsageAndExit(FileErrors.WRONG_FILETYPE);
//read file
string[] lines = File.ReadAllLines(inputFilename);
GoLangFile gData = new GoLangFile(lines);
DirectoryInfo dInfo = new DirectoryInfo(gData.PackageName);
if(!dInfo.Exists)
{
dInfo.Create();
dInfo.Refresh();
if(!dInfo.Exists)
{
Console.WriteLine("error: unable to create package folder");
Environment.Exit(-1);
}
}
gData.ExportStructsAsClasses(dInfo, "CerebroM", NOV_HEADER);
}
示例9: LoadIndex
public static IIndex LoadIndex(DirectoryInfo directory)
{
if (directory == null)
throw new ArgumentNullException("directory", "directory cannot be null");
directory.Refresh();
if (!directory.Exists)
throw new DirectoryNotFoundException(directory.FullName + " does not exist");
FileInfo[] topLevelFiles = directory.GetFiles("*.*", SearchOption.TopDirectoryOnly);
var toggleFile = topLevelFiles.FirstOrDefault(x => x.Name.Equals("toggle.txt", StringComparison.OrdinalIgnoreCase));
var totalIndexHeaders = topLevelFiles.Count(x => x.Extension.Equals(".cfx", StringComparison.OrdinalIgnoreCase) || x.Extension.Equals(".cfs", StringComparison.OrdinalIgnoreCase));
var segments = topLevelFiles.Count(x => x.Extension.Equals(".gen", StringComparison.OrdinalIgnoreCase));
if (toggleFile == null) {
// single
if (segments == 0 && totalIndexHeaders == 0)
return new Index(directory) { IndexStructure = IndexType.None };
return new Index(directory) { IndexStructure = IndexType.SingleIndex };
}
else {
// double or cyclic
DirectoryInfo mirrorDir = new DirectoryInfo(Path.Combine(directory.FullName, StaticValues.DirectoryMirror));
DirectoryInfo dirA = new DirectoryInfo(Path.Combine(directory.FullName, StaticValues.DirectoryA));
DirectoryInfo dirB = new DirectoryInfo(Path.Combine(directory.FullName, StaticValues.DirectoryB));
if (!dirA.Exists || !dirB.Exists)
return new DoubleIndex(directory) { IndexStructure = IndexType.None };
if (mirrorDir.Exists)
return new CyclicalIndex(directory);
return new DoubleIndex(directory);
}
}
示例10: GetAccountStorageDir
public DirectoryInfo GetAccountStorageDir(Guid accountId)
{
DirectoryInfo storageDir = new DirectoryInfo(StorageDir.FullName + Path.DirectorySeparatorChar + accountId.ToString());
if (!storageDir.Exists)
storageDir.Create();
storageDir.Refresh();
return storageDir;
}
示例11: GetStorageDir
public DirectoryInfo GetStorageDir(Guid newAct)
{
DirectoryInfo storageDir = new DirectoryInfo(GetStorageDir().FullName + Path.DirectorySeparatorChar + newAct.ToString());
if (!storageDir.Exists)
storageDir.Create();
storageDir.Refresh();
return storageDir;
}
示例12: Copying_To_Root_Directory_Should_Work
public void Copying_To_Root_Directory_Should_Work()
{
targetDir = new DirectoryInfo(Path.Combine(rootDirectory.FullName, "targetFoo"));
Assert.False(targetDir.Exists);
var targetFolder = provider.CopyFolder(originalFolder, targetDir.FullName);
targetDir.Refresh();
Assert.True(targetDir.Exists);
}
示例13: DirectoryFileBackup
public DirectoryFileBackup(FileInfo file, DirectoryInfo destination)
{
this.file = file;
this.destination = destination;
destination.Refresh();
if(!destination.Exists)
destination.Create();
}
示例14: NewFolder
public static void NewFolder(string s1)
{
var di = new DirectoryInfo(s1);
if (di.Parent != null && !di.Exists)
NewFolder(di.Parent.FullName);
if (di.Exists) return;
di.Create();
di.Refresh();
}
示例15: IgnoredCleanFileInfoEnumerator
public IgnoredCleanFileInfoEnumerator(DirectoryInfo directory)
{
directory.Refresh();
if (!directory.Exists)
{
throw new DirectoryNotFoundException(string.Format("Directory '{0}' does not exist", directory));
}
_directory = directory;
}