本文整理汇总了C#中System.IO.FileInfo.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.Equals方法的具体用法?C# FileInfo.Equals怎么用?C# FileInfo.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileInfo
的用法示例。
在下文中一共展示了FileInfo.Equals方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FileInfoEqualExperiment
public void FileInfoEqualExperiment()
{
Console.WriteLine("[*] Start Experiment how the FileInfo.Equal Function work.");
FileInfo file1 = new FileInfo(@"D:\CodeFolder\DotNet\Visual Studio 2013\Projects\ProcjetManager\ProcjetManager.sln");
FileInfo file2 = new FileInfo(@"D:\CodeFolder\DotNet\Visual Studio 2013\Projects\ProcjetManager\ProcjetManager.sln");
FileInfo file3 = new FileInfo(@"D:\CodeFolder\DotNet\Visual Studio 2013\Projects\ProcjetManager\ProcjetManager.v12.suo");
Console.WriteLine("-- Run FileInfo.Equal with to FileInfos have the same FullName : " + file1.Equals(file2));
Console.WriteLine(" FullName1 is [" + file1.FullName + "]");
Console.WriteLine(" FullName2 is [" + file2.FullName + "]");
Console.WriteLine("-- Run FileInfo.Equal with to FileInfos have fiffrent FullNames : " + file1.Equals(file3));
Console.WriteLine(" FullName1 is [" + file1.FullName + "]");
Console.WriteLine(" FullName2 is [" + file3.FullName + "]");
Console.WriteLine("[*] End Experiment how the FileInfo.Equal Function work.");
}
示例2: MakeRelative
public static String MakeRelative(String path, String fromPath)
{
List<String> pathComponents = new List<String>();
if (fromPath == null)
{
return path;
}
/* Use FileSystemInfo to canonicalize paths, ensure fromPath ends in a trailing \ to fromPath. */
path = new FileInfo(path).FullName;
fromPath = new FileInfo(fromPath + @"\").FullName;
if (fromPath.Equals(new FileInfo(path + @"\").FullName))
{
return ".";
}
/* Find the longest common base directory */
String baseDirectory = null;
for (int i = 0, lastSeparatorIdx = -1; ; i++)
{
if (i == path.Length || i == fromPath.Length || path[i] != fromPath[i])
{
baseDirectory = (lastSeparatorIdx >= 0) ? path.Substring(0, lastSeparatorIdx + 1) : null;
break;
}
else if (path[i] == Path.DirectorySeparatorChar)
{
lastSeparatorIdx = i;
}
}
/* No common directories (on different drives), no relativization possible */
if (baseDirectory == null)
{
return path;
}
/* Find the distance from the relativeFromPath to the baseDirectory */
String fromRelativeToBase = fromPath.Substring(baseDirectory.Length);
for (int i = 0; i < fromRelativeToBase.Length; i++)
{
if (fromRelativeToBase[i] == Path.DirectorySeparatorChar)
{
pathComponents.Add("..");
}
}
/* Add the path portion relative to the base */
pathComponents.Add(path.Substring(baseDirectory.Length));
return String.Join(new String(new char[] { Path.DirectorySeparatorChar }), pathComponents.ToArray());
}
示例3: FindItemByName
/// <summary>
/// Finds a project item in the received IVsHierarchy, given its name.
/// </summary>
/// <param name="projectHierarchy">The IVsHierarchy to start the search.</param>
/// <param name="name">The name of the item to locate.</param>
/// <returns>A <see cref="Project"/> reference or <see langword="null" /> if
/// it doesn't exist. Project can be C# or VB.</returns>
public static uint FindItemByName(IVsHierarchy projectHierarchy, string name)
{
uint foundItemID = VSConstants.VSITEMID_NIL;
EnumHierarchyItems(projectHierarchy,
delegate(IVsHierarchy hierarchy, uint itemid, int recursionLevel)
{
string itemName = null;
hierarchy.GetCanonicalName(itemid, out itemName);
if (itemName!=null)
{
itemName = new FileInfo(itemName).Name;
if (itemName.Equals(name))
{
foundItemID = itemid;
return false;
}
}
return true;
});
return foundItemID;
}
示例4: Initialize
//C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2015
public void Initialize() {
var commonStartMenupath = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu);
var programsDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"Microsoft\Windows\Start Menu\Programs");
var shortcuts = Directory.GetFiles(programsDirectory, "*", SearchOption.AllDirectories).Concat(Directory.GetFiles(commonStartMenupath, "*", SearchOption.AllDirectories));
foreach (var shortcut in shortcuts) {
// Console.WriteLine(shortcut);
var fileInfo = new FileInfo(shortcut);
if (fileInfo.Extension.Equals(".lnk", StringComparison.OrdinalIgnoreCase)) {
var happyName = fileInfo.Name.Substring(0, fileInfo.Name.Length - fileInfo.Extension.Length);
if (!commands.Any(x => x.Equals(happyName, StringComparison.OrdinalIgnoreCase))) {
commands = commands.Concat(new[] { happyName }).ToArray();
linkPathsByCommand.Add(happyName, shortcut);
// WshShellClass shell = new WshShellClass();
WshShell shell = new WshShell(); //Create a new WshShell Interface
IWshShortcut link = (IWshShortcut)shell.CreateShortcut(shortcut); //Link the interface to our shortcut
if (File.Exists(link.TargetPath)) {
var icon = Icon.ExtractAssociatedIcon(link.TargetPath);
var bmp = icon.ToBitmap();
iconsByCommandHappy.Add(happyName, bmp);
var fileName = new FileInfo(link.TargetPath).Name;
Console.WriteLine(fileName);
if (!fileName.Equals(happyName + ".exe", StringComparison.OrdinalIgnoreCase) &&
!commands.Any(x => x.Equals(fileName, StringComparison.OrdinalIgnoreCase))) {
commands = commands.Concat(new[] { fileName }).ToArray();
exectuablesByFileName.Add(fileName, link.TargetPath);
iconsByFileName.Add(fileName, bmp);
}
} else {
var icon = Icon.ExtractAssociatedIcon(shortcut);
var bmp = icon.ToBitmap();
iconsByCommandHappy.Add(happyName, bmp);
}
}
}
}
}
示例5: DownloadFiles
public void DownloadFiles(object sender, AsyncCompletedEventArgs e)
{
//We stop the stopwatch.
//sw.Stop();
try
{
for (int intCurrFile = sucessfullyDownloadedCount; intCurrFile < FileAddressList.GetLength(0); intCurrFile++)
{
sw.Reset();
Application.DoEvents();
if (FileAddressList[intCurrFile,0] == null)
{
break;
}
CurrentFileDLName = Path.GetFileName((new Uri(FileAddressList[intCurrFile, 0])).AbsolutePath);
label8.Text = "Part " + (intCurrFile + 1) + " of " + FileAddressList.GetLength(0);
progressBar2.Value = 100 * intCurrFile / FileAddressList.GetLength(0);
if (cVersion.IsMlkSimAC3Package(CurrentFileDLName) && ActionNextLabel.Text == "Action: uninstall, but keep songs, then install updates")
continue;
if (File.Exists(Path.Combine(TempPath, CurrentFileDLName)))
{
string GenByte = new System.IO.FileInfo(Path.Combine(TempPath, CurrentFileDLName)).Length.ToString();
//if it match, then we download the next file!
if (FileAddressList[intCurrFile, 1].Equals(GenByte) == false && GenByte.Equals("483491840") ==false)
{
// Delete the file if it exist.
if (File.Exists(Path.Combine(TempPath, CurrentFileDLName))) { File.Delete(Path.Combine(TempPath, CurrentFileDLName)); }
// Ask user to redownload or cancel.
if (DownloadRetryCount < 5)
{
Downloaded = null;
Downloaded2 = null;
GenByte = null;
Timeout.Stop();
DownloadRetryCount += 1;
DownloadAndInstallButton_Click(null, null);
break;
}
else
{
DownloadRetryCount = 3;
DialogResult dialogResult = MessageBox.Show("the downloaded file " + CurrentFileDLName + " is corrupted. Please make sure you use a stable internet connection. Do you want to retry downloading?", "File verification FAILED", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
Downloaded = null;
Downloaded2 = null;
GenByte = null;
Timeout.Stop();
DownloadAndInstallButton_Click(null, null);
break;
}
else if (dialogResult == DialogResult.No)
{
cHelper.ShowErrorMessageDialog("User aborted after corruped file downloads. Closing application now.", "", "");
break;
}
}
}
else
{
sucessfullyDownloadedCount = Math.Max(sucessfullyDownloadedCount, (intCurrFile+1));
}
}
// If the file doesn't exist or has been detected as incorrect and deleted, we QUACK a copy!
else
{
Canard = new WebClient();
Canard.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFiles);
Canard.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
sw.Start();
Canard.DownloadFileAsync(new Uri(FileAddressList[intCurrFile, 0]), Path.Combine(TempPath, CurrentFileDLName));
progressBar1.Value = 0;
break;
}
}
if (sucessfullyDownloadedCount == FileAddressList.GetLength(0))
{
//all files are now successfully downloaded.
progressBar2.Value = 100;
InstallationFunctionThread();
}
//We start the stopwatch to calculate progress.
}
catch (Exception ex)
{
cHelper.ShowErrorMessageDialog(ex.Message, ex.StackTrace, "DownloadFiles");
}
}
示例6: GetFile
/// <summary>
/// Retrieves a file from the destination and copies it to the specified path.
/// </summary>
/// <param name="fromPath">the file to retrieve from the destination (relative to basePath)</param>
/// <param name="toPath">the local location to save the contents of the file (fully-qualifed path)</param>
/// <param name="isBinary">true if the file is binary</param>
override public bool GetFile(String fromPath, string toPath, bool isBinary)
{
fromPath = Path.Combine(m_path, fromPath);
FileInfo fromFile = new FileInfo(fromPath);
FileInfo toFile = new FileInfo(fromPath);
if (fromFile.Equals(toFile))
{
//then the source is the same as the destination, so ignore
return true;
}
try
{
// Delete existing file
if (File.Exists(toPath))
File.Delete(toPath);
// Copy the file
File.Copy(fromPath, toPath);
return true;
}
catch (Exception e)
{
if (RetryOnException(e))
return false;
else
{
SiteDestinationException ex = new SiteDestinationException(e, SiteDestinationException.TransferException, GetType().Name, 0);
ex.DestinationExtendedMessage = e.Message;
throw ex;
}
}
}
示例7: AreEqual
public static bool AreEqual(string path1, string path2)
{
var fullName = new System.IO.FileInfo(path1).FullName;
var fullName2 = new System.IO.FileInfo(path2).FullName;
return fullName.Equals(fullName2, StringComparison.InvariantCultureIgnoreCase);
}