public void GetFileAttributesExBasic() { string tempPath = FileMethods.GetTempPath(); var info = FileMethods.GetFileAttributesEx(tempPath); info.Attributes.Should().HaveFlag(FileAttributes.FILE_ATTRIBUTE_DIRECTORY); }
public void GetFileAttributesExBasic() { string tempPath = FileMethods.GetTempPath(); var info = FileMethods.GetFileAttributesEx(tempPath); info.dwFileAttributes.Should().HaveFlag(FileAttributes.Directory); }
public void CopyFileBasic() { using (var temp = new TestFileCleaner()) { string source = temp.GetTestPath(); using (var file = FileMethods.CreateFile(source, DesiredAccess.GENERIC_READ, ShareMode.FILE_SHARE_READWRITE, CreationDisposition.CREATE_NEW)) { file.IsInvalid.Should().BeFalse(); } string destination = temp.GetTestPath(); FileMethods.CopyFile(source, destination); var info = FileMethods.GetFileAttributesEx(destination); info.Attributes.Should().NotHaveFlag(FileAttributes.FILE_ATTRIBUTE_DIRECTORY); } }
public void CopyFileBasic() { using (var temp = new TestFileCleaner()) { string source = temp.GetTestPath(); using (var file = FileMethods.CreateFile(source, CreationDisposition.CreateNew, DesiredAccess.GenericRead)) { file.IsInvalid.Should().BeFalse(); } string destination = temp.GetTestPath(); FileMethods.CopyFile(source, destination); var info = FileMethods.GetFileAttributesEx(destination); info.dwFileAttributes.Should().NotHaveFlag(FileAttributes.Directory); } }
/// <summary> /// Equivalent implementation of GetExpandedName that doesn't have a path length limit. /// </summary> /// <remarks> /// There are possibly quirks with ASCII handling that this function may not replicate. Files /// that end in a DBCS character get some special handling. /// </remarks> public unsafe static string GetExpandedNameEx(string path, bool filenameOnly = false) { // Need to end with underscore or be at least as long as the header. if (string.IsNullOrEmpty(path)) { return(path); } path = Paths.TrimTrailingSeparators(path); if (path[path.Length - 1] != '_' || FileMethods.GetFileAttributesEx(path).nFileSize <= (ulong)sizeof(LzxHeader)) { return(filenameOnly ? Paths.GetLastSegment(path) : path); } char replacement; using (var file = FileMethods.CreateFile(path, CreationDisposition.OpenExisting, DesiredAccess.GenericRead, ShareModes.Read)) { LzxHeader header = new LzxHeader(); if (FileMethods.ReadFile(file, (byte *)&header, (uint)sizeof(LzxHeader)) < sizeof(LzxHeader)) { return(path); } replacement = char.ToUpperInvariant((char)header.extensionChar); } if (filenameOnly) { path = Paths.GetLastSegment(path); } bool noExtension = path.Length == 1 || path[path.Length - 2] == '.'; if (replacement == (char)0x00) { return(path.Substring(0, path.Length - (noExtension ? 2 : 1))); } return(Strings.ReplaceChar(path, path.Length - 1, replacement)); }
public void SetFileAttributesBasic() { string tempPath = FileMethods.GetTempPath(); string tempFileName = FileMethods.GetTempFileName(tempPath, "tfn"); try { var originalInfo = FileMethods.GetFileAttributesEx(tempFileName); originalInfo.Attributes.Should().NotHaveFlag(FileAttributes.FILE_ATTRIBUTE_READONLY); FileMethods.SetFileAttributes(tempFileName, originalInfo.Attributes | FileAttributes.FILE_ATTRIBUTE_READONLY); var newInfo = FileMethods.GetFileAttributesEx(tempFileName); newInfo.Attributes.Should().HaveFlag(FileAttributes.FILE_ATTRIBUTE_READONLY); FileMethods.SetFileAttributes(tempFileName, originalInfo.Attributes); newInfo = FileMethods.GetFileAttributesEx(tempFileName); newInfo.Attributes.Should().NotHaveFlag(FileAttributes.FILE_ATTRIBUTE_READONLY); } finally { FileMethods.DeleteFile(tempFileName); } }