コード例 #1
0
 public static void Delete(string fileName)
 {
     if (!WinAPI.KERNEL32.DeleteFileW(@"\\?\" + UnicodePath.GetFullPath(fileName)))
     {
         throw new System.ComponentModel.Win32Exception();
     }
 }
コード例 #2
0
 public static void Copy(string sourceFileName, string destinationFileName)
 {
     if (!WinAPI.KERNEL32.CopyFileW(@"\\?\" + UnicodePath.GetFullPath(sourceFileName), @"\\?\" + UnicodePath.GetFullPath(destinationFileName), true))
     {
         throw new System.ComponentModel.Win32Exception();
     }
 }
コード例 #3
0
        public static bool Exists(string path)
        {
            WinAPI.KERNEL32.WIN32_FIND_DATA findData;
            SafeFindHandle findHandle;
            List <string>  files  = new List <string>();
            bool           exists = false;

            findHandle = WinAPI.KERNEL32.FindFirstFileW(@"\\?\" + UnicodePath.GetFullPath(path), out findData);
            try {
                if (findHandle.IsInvalid)
                {
                    int lastErrorCode = Marshal.GetLastWin32Error();
                    if (lastErrorCode != WinAPI.KERNEL32.ERROR_NO_MORE_FILES && lastErrorCode != WinAPI.KERNEL32.ERROR_FILE_NOT_FOUND && lastErrorCode != WinAPI.KERNEL32.ERROR_PATH_NOT_FOUND)
                    {
                        throw new System.ComponentModel.Win32Exception();
                    }
                }
                else
                {
                    exists = true;
                }
            } finally {
                findHandle.Close();
            }
            return(exists);
        }
コード例 #4
0
 public static void Delete(string path)
 {
     if (!WinAPI.KERNEL32.RemoveDirectoryW(@"\\?\" + UnicodePath.GetFullPath(path)))
     {
         throw new System.ComponentModel.Win32Exception();
     }
 }
コード例 #5
0
 public static void Create(string path)
 {
     if (!WinAPI.KERNEL32.CreateDirectoryW(@"\\?\" + UnicodePath.GetFullPath(path), IntPtr.Zero))
     {
         throw new System.ComponentModel.Win32Exception();
     }
 }
コード例 #6
0
        public static void Create(string fileName)
        {
            SafeFileHandle fileHandle = WinAPI.KERNEL32.CreateFileW(
                @"\\?\" + UnicodePath.GetFullPath(fileName),
                FileAccess.Write,
                FileShare.None,
                IntPtr.Zero,
                FileMode.CreateNew,
                FileAttributes.Normal,
                IntPtr.Zero);

            if (fileHandle.IsInvalid)
            {
                throw new System.ComponentModel.Win32Exception();
            }

            fileHandle.Close();
        }
コード例 #7
0
        public static string[] GetDirectories(string path)
        {
            WinAPI.KERNEL32.WIN32_FIND_DATA findData;
            SafeFindHandle findHandle;
            List <string>  directories = new List <string>();
            int            win32Error;
            string         basePath = UnicodePath.GetFullPath(path);

            findHandle = WinAPI.KERNEL32.FindFirstFileW(@"\\?\" + UnicodePath.GetFullPath(path + @"\*"), out findData);

            if (findHandle.IsInvalid)
            {
                win32Error = Marshal.GetLastWin32Error();
                if (win32Error != WinAPI.KERNEL32.ERROR_NO_MORE_FILES && win32Error != WinAPI.KERNEL32.ERROR_FILE_NOT_FOUND && win32Error != WinAPI.KERNEL32.ERROR_PATH_NOT_FOUND)
                {
                    throw new System.ComponentModel.Win32Exception();
                }
                return(directories.ToArray());
            }

            try {
                do
                {
                    if ((findData.FileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
                    {
                        if (findData.FileName != "." && findData.FileName != "..")
                        {
                            directories.Add(string.Format("{0}{1}{2}", basePath, Path.DirectorySeparatorChar, findData.FileName));
                        }
                    }
                } while (WinAPI.KERNEL32.FindNextFileW(findHandle, out findData));

                win32Error = Marshal.GetLastWin32Error();

                if (win32Error != WinAPI.KERNEL32.ERROR_NO_MORE_FILES)
                {
                    throw new System.ComponentModel.Win32Exception(win32Error);
                }
            } finally {
                findHandle.Close();
            }

            return(directories.ToArray());
        }