Exemplo n.º 1
0
        public static string CreateBackupFileNamePattern(string fileName, bool keepExt)
        {
            if (keepExt)
            {
                string fileNameWithoutExt;
                string ext;
                FileRollUtil.GetFileNameAndExt(fileName, out fileNameWithoutExt, out ext);

                var escapedFileName = fileNameWithoutExt.Replace(".", "\\.");
                if (ext == null)
                {
                    //{fileName}.{yyyyMMdd}.{index}
                    return($"{escapedFileName}(\\.([0-9]*))?(\\.([0-9]*))?");
                }
                else
                {
                    //{fileName}.{yyyyMMdd}.{index}.{ext}
                    return($"{escapedFileName}(\\.([0-9]*))?(\\.([0-9]*))?\\.{ext}");
                }
            }
            else
            {
                var escapedFileName = fileName.Replace(".", "\\.");
                return($"{escapedFileName}(\\.([0-9]*))?(\\.([0-9]*))?");
            }
        }
Exemplo n.º 2
0
 protected override string ResolveRollName(IndexedFileInfo m)
 {
     if (!_keepExt)
     {
         return(Path.Combine(_dir, $"{_fileName}.{m.index + 1}"));
     }
     else
     {
         string baseFileNameWithoutExt, ext;
         FileRollUtil.GetFileNameAndExt(_fileName, out baseFileNameWithoutExt, out ext);
         var path = Path.Combine(_dir, $"{baseFileNameWithoutExt}.{m.index + 1}");
         if (ext != null)
         {
             path += $".{ext}";
         }
         return(path);
     }
 }
Exemplo n.º 3
0
        public static string GetDatedFileName(string baseFileName, System.DateTime date, int index = 0, bool keepExts = false)
        {
            var dateStr = date.ToString("yyyyMMdd");

            if (!keepExts)
            {
                if (index == 0)
                {
                    return($"{baseFileName}.{dateStr}");
                }
                else
                {
                    return($"{baseFileName}.{dateStr}.{index}");
                }
            }
            else
            {
                string fileNameWithoutExt, ext;
                if (FileRollUtil.GetFileNameAndExt(baseFileName, out fileNameWithoutExt, out ext))
                {
                    if (index == 0)
                    {
                        return($"{fileNameWithoutExt}.{dateStr}.{ext}");
                    }
                    else
                    {
                        return($"{fileNameWithoutExt}.{dateStr}.{index}.{ext}");
                    }
                }
                else
                {
                    if (index == 0)
                    {
                        return($"{baseFileName}.{dateStr}");
                    }
                    else
                    {
                        return($"{baseFileName}.{dateStr}.{index}");
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static string CreateBackupFileNamePattern(string fileName, bool keepExt)
        {
            string baseFileName;
            string ext;

            if (keepExt)
            {
                FileRollUtil.GetFileNameAndExt(fileName, out baseFileName, out ext);
            }
            else
            {
                baseFileName = fileName;
                ext          = null;
            }
            baseFileName = baseFileName.Replace(".", "\\.");
            string pattern = $"({baseFileName})(\\.([0-9]*))?";

            if (ext != null)
            {
                pattern += $"\\.({ext})";
            }
            return(pattern);
        }