本文整理汇总了C#中System.IO.Directory.GetName方法的典型用法代码示例。如果您正苦于以下问题:C# Directory.GetName方法的具体用法?C# Directory.GetName怎么用?C# Directory.GetName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Directory
的用法示例。
在下文中一共展示了Directory.GetName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SyncDirectory
public async Task SyncDirectory(Directory dir, string parentId)
{
// Get directories of parent and find this folder's id in drive (if exists)
IList<DriveFile> parentChildren = mDMgr.FetchChildrenDirectories(parentId);
string dirId = "";
foreach (DriveFile file in parentChildren)
if (file.Title.Equals(dir.GetName()))
dirId = file.Id;
// Folder does not exist so create it
if (dirId.Equals(""))
dirId = mDMgr.CreateDirectory(dir.GetName(), dir.GetName(), parentId).Id;
// Get files and folders of this directory in drive
IList<DriveFile> children = mDMgr.FetchChildren(dirId);
// Start syncing this directory
// Check the drive for any files and folders that do not exist locally and delete them
List<DriveFile> foldersToDelete = new List<DriveFile>();
foreach (DriveFile dFile in children)
{
bool existsLocally = false;
foreach (string file in dir.GetFiles())
{
if (dFile.Title.Equals(Path.GetFileName(file)))
{
existsLocally = true;
break;
}
}
foreach (Directory subdir in dir.getSubDirectories())
{
if(dFile.Title.Equals(subdir.GetName()))
{
existsLocally = true;
break;
}
}
// Delete if it doesn't exist
if (!existsLocally)
{
string type;
if (DriveManager.IsDirectory(dFile))
type = "directory";
else
type = "file";
Console.WriteLine("Deleting " + type + ": " + dFile.Title);
mDMgr.DeleteFile(dFile.Id);
}
}
IList<DriveFile> childrenFiles = children.Where(d => !(DriveManager.IsDirectory(d))).ToList();
// Upload or update files
foreach (string file in dir.GetFiles())
{
// Get simple filename
string filename = Path.GetFileName(file);
// Try to find it on drive
DriveFile fileInDrive = null;
foreach (DriveFile dFile in childrenFiles)
{
if (dFile.Title.Equals(filename))
{
fileInDrive = dFile;
break;
}
}
// If didn't found it, upload it, else update it
if (fileInDrive != null)
{
// If the local file is modified since the last time it was uploaded on drive, update it.
// If not, just leave it as it is. In case of error (eg. the fileInDrive.ModifiedDate is null)
// just upload it anyway. Better be safe than sorry :)
bool shouldUpload = true;
if (fileInDrive.ModifiedDate.HasValue)
{
DateTime localDate = System.IO.File.GetLastWriteTime(file);
DateTime driveDate = (DateTime)fileInDrive.ModifiedDate;
if (DateTime.Compare(localDate, driveDate) <= 0)
shouldUpload = false;
}
if (shouldUpload)
{
mUploader.SetupFile(file, file, dirId);
await mUploader.Update();
}
else
{
Console.WriteLine("Skipped -- " + file);
}
}
//.........这里部分代码省略.........