Hej wszystkim forumowiczom :)
Mam klasę:
public class File
{
public static string Name(string path)
{
return System.IO.Path.GetFileNameWithoutExtension(path);
}
public static string Extension(string path)
{
return (HasExtension(path)) ? path.Substring(path.LastIndexOf('.')) : null;
}
public static bool Exist(string path)
{
return System.IO.File.Exists(path);
}
public static bool HasExtension(string path)
{
return System.IO.Path.HasExtension(path);
}
public static List<string> GetFiles(DragEventArgs e)
{
List<string> OutputList = new List<string>();
e.Effects = DragDropEffects.All;
string[] DroppedFiles = (string[])e.Data.GetData(DataFormats.FileDrop);
GetFiles(DroppedFiles, OutputList);
return OutputList;
}
public static void GetFiles(string[] files, List<string> List)
{
if (files == null)
return;
foreach (string Path in files)
{
if (!HasExtension(Path))
GetFiles(GetAllFilesFromDirectory(Path), List);
else
{
MessageBox.Show(Extension(Path));
if (Extension(Path).Contains(".Ink"))
{
MessageBox.Show("...");
GetFiles(GetAllFilesFromShortcut(Path), List);
}
else
{
List.Add(Path);
}
}
}
return;
}
public static string[] GetAllFilesFromDirectory(string directory)
{
IEnumerable<string> output = Directory.EnumerateFileSystemEntries(directory, "*", SearchOption.AllDirectories);
return (output != null) ? output.ToArray() : null;
}
public static string[] GetAllFilesFromShortcut(string Path)
{
if (Path == null)
return null;
WshShell shell = new WshShell();
IWshShortcut link = (IWshShortcut)shell.CreateShortcut(Path);
MessageBox.Show(link.TargetPath);
Path = link.TargetPath;
if (!HasExtension(Path))
return GetAllFilesFromDirectory(Path);
else
{
if (Extension(Path).Contains(".Ink"))
{
return GetAllFilesFromShortcut(Path);
}
else
{
return new List<string> { Path }.ToArray();
}
}
}
Nie potrafi mi poprawnie porównać, czy rozszerzenie jest równe .Ink
MessageBox zaraz przedtem pokazuje wynik ".Ink", jednak jak porównuje i to zwraca false. Proszę o pomoc w tej części:
if (!HasExtension(Path))
GetFiles(GetAllFilesFromDirectory(Path), List);
else
{
MessageBox.Show(Extension(Path));
if (Extension(Path).Contains(".Ink"))
{
MessageBox.Show("...");
GetFiles(GetAllFilesFromShortcut(Path), List);
}