Exemple #1
0
        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);
            }
        }
Exemple #2
0
 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);
     }
 }
Exemple #3
0
 public DateTime GetLastWriteTime(string path)
 {
     if (!IsLongPath(path))
     {
         return(File.GetLastWriteTime(path));
     }
     else
     {
         return(Win32LongPathFile.GetLastWriteTime(path));
     }
 }
Exemple #4
0
 public void DeleteFile(string path)
 {
     if (!IsLongPath(path))
     {
         File.Delete(path);
     }
     else
     {
         Win32LongPathFile.Delete(path);
     }
 }
Exemple #5
0
 public void SetFileAttribute(string path, FileAttributes attribute)
 {
     if (!IsLongPath(path))
     {
         File.SetAttributes(path, attribute);
     }
     else
     {
         Win32LongPathFile.SetAttributes(path, attribute);
     }
 }
Exemple #6
0
 public FileAttributes GetFileAttributes(string path)
 {
     if (path.Length < Win32FileSystem.MAX_PATH)
     {
         return(File.GetAttributes(path));
     }
     else
     {
         return(Win32LongPathFile.GetAttributes(path));
     }
 }
Exemple #7
0
 public DateTime GetLastWriteTime(string path)
 {
     if (path.Length < 260)
     {
         return(File.GetLastWriteTime(path));
     }
     else
     {
         return(Win32LongPathFile.GetLastWriteTime(path));
     }
 }
Exemple #8
0
        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();
         }
     }
 }
Exemple #10
0
        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)));
            }
        }
Exemple #11
0
 public bool IsLongPath(string path)
 {
     return(Win32LongPathFile.IsLongPath(path));
 }