コード例 #1
0
        public static void AppendFileName(string filePath)
        {
            Encoding fileEncoding = FileHandling.GetFileEncoding(filePath);
            string   fileName     = Path.GetFileName(filePath);

            byte[] fileNameBytes = fileEncoding.GetBytes(fileName);
            using var fileStream = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.Read, Constants.FileStreamBufferSize, FileOptions.RandomAccess);
            fileStream.Write(fileNameBytes, offset: 0, fileNameBytes.Length);
        }
コード例 #2
0
 public static void RemoveAppendedFileName(string inputFilePath)
 {
     try
     {
         File.SetAttributes(inputFilePath, FileAttributes.Normal);
         Encoding fileEncoding  = FileHandling.GetFileEncoding(inputFilePath);
         string   fileName      = Path.GetFileName(inputFilePath);
         byte[]   fileNameBytes = fileEncoding.GetBytes(fileName);
         using var fileStream = new FileStream(inputFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read, Constants.FileStreamBufferSize, FileOptions.RandomAccess);
         fileStream.SetLength(fileStream.Length - fileNameBytes.Length);
     }
     catch (Exception ex) when(ExceptionFilters.FileAccess(ex))
     {
         Logging.LogException(ex.ToString(), Logging.Severity.Error);
         DisplayMessage.FilePathException(inputFilePath, ex.GetType().Name, "Unable to remove appended file name.");
     }
 }