public void MoveFile(string sourcePath, string targetPath, bool bCreateFolder = false) { if (bCreateFolder) { string targetDirectoryName = null; if (!IsLongPath(targetPath)) { targetDirectoryName = Path.GetDirectoryName(targetPath); } else { string targetFileName = Path.GetFileName(targetPath); targetDirectoryName = targetPath.Substring(0, targetPath.Length - targetFileName.Length); } if (!DirectoryExists(targetDirectoryName)) { CreateDirectory(targetDirectoryName); } } if (!IsLongPath(sourcePath) && !IsLongPath(targetPath)) { File.Move(sourcePath, targetPath); } else { Win32LongPathFile.Move(sourcePath, targetPath); } }
public void CopyFile(string sourcePath, string targetPath, bool bOverwrite = false) { if (!IsLongPath(sourcePath) && !IsLongPath(targetPath)) { File.Copy(sourcePath, targetPath, bOverwrite); } else { Win32LongPathFile.Copy(sourcePath, targetPath, bOverwrite); } }
public DateTime GetLastWriteTime(string path) { if (!IsLongPath(path)) { return(File.GetLastWriteTime(path)); } else { return(Win32LongPathFile.GetLastWriteTime(path)); } }
public void DeleteFile(string path) { if (!IsLongPath(path)) { File.Delete(path); } else { Win32LongPathFile.Delete(path); } }
public void SetFileAttribute(string path, FileAttributes attribute) { if (!IsLongPath(path)) { File.SetAttributes(path, attribute); } else { Win32LongPathFile.SetAttributes(path, attribute); } }
public FileAttributes GetFileAttributes(string path) { if (path.Length < Win32FileSystem.MAX_PATH) { return(File.GetAttributes(path)); } else { return(Win32LongPathFile.GetAttributes(path)); } }
public DateTime GetLastWriteTime(string path) { if (path.Length < 260) { return(File.GetLastWriteTime(path)); } else { return(Win32LongPathFile.GetLastWriteTime(path)); } }
public bool FileExists(string path) { bool bExists = false; if (!IsLongPath(path)) { bExists = System.IO.File.Exists(path); } else { bExists = Win32LongPathFile.Exists(path); } int code = System.Runtime.InteropServices.Marshal.GetLastWin32Error(); return(bExists); }
private static void DeleteDirectoriesRecrusive(string[] directories) { foreach (string directory in directories) { var files = Win32LongPathDirectory.GetFiles(GetWin32LongPath(directory), null, System.IO.SearchOption.TopDirectoryOnly); foreach (string file in files) { Win32LongPathFile.Delete(GetWin32LongPath(file)); } directories = Win32LongPathDirectory.GetDirectories(directory, null, System.IO.SearchOption.TopDirectoryOnly); DeleteDirectoriesRecrusive(directories); bool ok = Win32FileSystem.RemoveDirectory(GetWin32LongPath(directory)); if (!ok) { ThrowWin32Exception(); } } }
public bool IsFileSame(string file1, string file2) { if (IsFileSameByLastChangeOnly) { if (!IsLongPath(file1) && !IsLongPath(file2)) { DateTime time1 = File.GetLastWriteTime(file1); DateTime time2 = File.GetLastWriteTime(file2); return(time1 == time2); } else { DateTime time1 = Win32LongPathFile.GetLastWriteTime(file1); DateTime time2 = Win32LongPathFile.GetLastWriteTime(file2); return(time1 == time2); } } else { return(File.ReadLines(file1).SequenceEqual(File.ReadLines(file2))); } }
public bool IsLongPath(string path) { return(Win32LongPathFile.IsLongPath(path)); }