Пример #1
0
        public static void CombineFiles(string srcFilePathPattern, string destFilePath, int bufferSize = 4096, string EOFDelimiter = null)
        {
            ChoGuard.ArgumentNotNullOrEmpty(srcFilePathPattern, "srcFilePathPattern");
            ChoGuard.ArgumentNotNullOrEmpty(destFilePath, "destFilePath");

            if (EOFDelimiter == null)
            {
                EOFDelimiter = Environment.NewLine;
            }

            using (var outputStream = File.OpenWrite(destFilePath))
            {
                foreach (string fp in ChoDirectory.GetFilesBeginWith(srcFilePathPattern).OrderBy(f => f, StringComparer.CurrentCultureIgnoreCase))
                {
                    if (new FileInfo(fp).Length == 0)
                    {
                        continue;
                    }
                    using (var inputStream = File.OpenRead(fp))
                    {
                        if (outputStream.Position != 0)
                        {
                            outputStream.Write(EOFDelimiter);
                        }

                        // Buffer size can be passed as the second argument.
                        inputStream.CopyTo(outputStream, bufferSize);
                    }
                }
            }
        }
Пример #2
0
        public static void DeleteAll(string srcFilePathPattern)
        {
            ChoGuard.ArgumentNotNullOrEmpty(srcFilePathPattern, "srcFilePathPattern");

            foreach (string fp in ChoDirectory.GetFilesBeginWith(srcFilePathPattern).OrderBy(f => f, StringComparer.CurrentCultureIgnoreCase))
            {
                File.Delete(fp);
            }
        }