Ejemplo n.º 1
0
 //public static int GetLastDirectoryIndex(string dir, string dirname, out int maxIndexLength)
 public static int GetLastDirectoryIndex(string dir, string dirname, TextIndexOption option, out int maxIndexLength)
 {
     maxIndexLength = 0;
     if (!zDirectory.Exists(dir))
     {
         return(0);
     }
     //return Directory.EnumerateDirectories(dir).Select(d => zPath.GetFileName(d)).zGetLastTextIndex(dirname, out maxIndexLength);
     return(zfile.GetLastTextIndex(zDirectory.EnumerateDirectories(dir).Select(d => zPath.GetFileName(d)), dirname, option, out maxIndexLength));
 }
Ejemplo n.º 2
0
        /// <summary></summary>
        /// <param name="texts"></param>
        /// <param name="name"></param>
        /// <param name="maxIndexLength">ex : "000123" maxIndexLength = 6</param>
        /// <returns></returns>
        //public static int GetLastTextIndex(IEnumerable<string> texts, string name, out int maxIndexLength)
        public static int GetLastTextIndex(IEnumerable <string> texts, string name, TextIndexOption option, out int maxIndexLength)
        {
            if (name != null)
            {
                name = name.ToLower();
            }
            Regex regex;

            if (option == TextIndexOption.NumberAfter)
            {
                regex = __textIndexNumberAfter;
            }
            else // if (option == TextIndexOption.NumberBefore)
            {
                regex = __textIndexNumberBefore;
            }
            int lastIndex = 0;

            maxIndexLength = 0;
            foreach (string text in texts)
            {
                Match match = regex.Match(text);
                if (match.Success)
                {
                    //if (name != null && match.Groups[2].Value.ToLower() != name)
                    if (name != null && match.Groups["name"].Value.ToLower() != name)
                    {
                        continue;
                    }
                    //int index = int.Parse(match.Groups[1].Value);
                    int index = int.Parse(match.Groups["number"].Value);
                    if (index > lastIndex)
                    {
                        lastIndex = index;
                    }
                    int indexLength = match.Groups[1].Value.Length;
                    if (indexLength > maxIndexLength)
                    {
                        maxIndexLength = indexLength;
                    }
                }
            }
            return(lastIndex);
        }
Ejemplo n.º 3
0
 /// <summary></summary>
 /// <param name="texts"></param>
 /// <param name="name"></param>
 /// <param name="maxIndexLength">ex : "000123" maxIndexLength = 6</param>
 /// <returns></returns>
 //public static int GetLastTextIndex(IEnumerable<string> texts, string name, out int maxIndexLength)
 public static int GetLastTextIndex(IEnumerable<string> texts, string name, TextIndexOption option, out int maxIndexLength)
 {
     if (name != null)
         name = name.ToLower();
     Regex regex;
     if (option == TextIndexOption.NumberAfter)
         regex = __textIndexNumberAfter;
     else // if (option == TextIndexOption.NumberBefore)
         regex = __textIndexNumberBefore;
     int lastIndex = 0;
     maxIndexLength = 0;
     foreach (string text in texts)
     {
         Match match = regex.Match(text);
         if (match.Success)
         {
             //if (name != null && match.Groups[2].Value.ToLower() != name)
             if (name != null && match.Groups["name"].Value.ToLower() != name)
                 continue;
             //int index = int.Parse(match.Groups[1].Value);
             int index = int.Parse(match.Groups["number"].Value);
             if (index > lastIndex)
                 lastIndex = index;
             int indexLength = match.Groups[1].Value.Length;
             if (indexLength > maxIndexLength)
                 maxIndexLength = indexLength;
         }
     }
     return lastIndex;
 }
Ejemplo n.º 4
0
 //public static int GetLastFileNameIndex(string dir, string filename, out int maxIndexLength)
 public static int GetLastFileNameIndex(string dir, string filename, TextIndexOption option, out int maxIndexLength)
 {
     maxIndexLength = 0;
     if (!zDirectory.Exists(dir))
         return 0;
     //return Directory.EnumerateFiles(dir).Select(d => zPath.GetFileName(d)).zGetLastTextIndex(filename, out maxIndexLength);
     //return Directory.EnumerateFiles(dir).Select(d => zPath.GetFileName(d)).zGetLastTextIndex(filename, option, out maxIndexLength);
     return GetLastTextIndex(zDirectory.EnumerateFiles(dir).Select(d => zPath.GetFileName(d)), filename, option, out maxIndexLength);
 }
Ejemplo n.º 5
0
 public static int GetLastFileNameIndex(string dir, string filename = null, TextIndexOption option = TextIndexOption.NumberBefore)
 {
     int maxIndexLength;
     return GetLastFileNameIndex(dir, filename, option, out maxIndexLength);
 }
Ejemplo n.º 6
0
        //public static string GetNewIndexedFileName(string path)
        //{
        //    int index; string fileMask;
        //    return GetNewIndexedFileName(path, out index, out fileMask);
        //}

        //public static string GetNewIndexedFileName(string path, out int index, out string fileMask)
        //{
        //    index = 0;
        //    fileMask = null;
        //    if (path == null) return null;

        //    // zPath.GetDirectoryName(path);
        //    // exception générée et capturée par le debugger mais qui n'apparait pas à l'exécution
        //    // System.NotSupportedException "The given path's format is not supported."
        //    // path = "C:\\pib\\prog\\tools\\runsource\\run\\RunSource_{0:00000}.*"
        //    string dir = zPath.GetDirectoryName(path);
        //    int l = dir.Length + 1;
        //    string file = path.Substring(l, path.Length - l);

        //    string ext = null;
        //    int i = file.LastIndexOf('.');
        //    if (i != -1)
        //    {
        //        ext = file.Substring(i, file.Length - i);
        //        file = file.Substring(0, i);
        //    }

        //    if (!__rgGetNewIndexedFileName.IsMatch(file)) file = "{0:0000}_" + file;
        //    index = GetLastFileNameIndex(dir, file, ext) + 1;

        //    fileMask = file;
        //    if (ext != null) fileMask += ext;
        //    fileMask = zPath.Combine(dir, fileMask);
        //    return string.Format(fileMask, index);
        //}

        //public static string GetNewIndexedDirectory(string path)
        //{
        //    if (path == null) return null;

        //    string dir = zPath.GetDirectoryName(path);
        //    int l = dir.Length + 1;
        //    string dirname = path.Substring(l, path.Length - l);

        //    if (!__rgGetNewIndexedFileName.IsMatch(dirname))
        //        dirname = "{0:0000}_" + dirname;
        //    int iIndex = GetLastDirectoryIndex(dir, dirname) + 1;
        //    return zPath.Combine(dir, string.Format(dirname, iIndex));
        //}

        //public static int GetLastFileNameIndex(string dir, string file, string ext)
        //{
        //    if (!Directory.Exists(dir))
        //    {
        //        Directory.CreateDirectory(dir);
        //        return 0;
        //    }
        //    string sRegex;
        //    string sFileSearch;
        //    Match match = __rgGetNewIndexedFileName.Match(file);
        //    if (!match.Success)
        //    {
        //        sFileSearch = "*_*" + file;
        //        sRegex = "^([0-9]+)_" + file;
        //    }
        //    else
        //    {
        //        sRegex = "^" + match.zReplace(file, "([0-9]+)");
        //        sFileSearch = match.zReplace(file, "*");
        //        if (!sFileSearch.EndsWith("*")) sFileSearch += "*";
        //    }
        //    if (ext != null && ext != "")
        //        sFileSearch += ext;
        //    else
        //        sFileSearch += ".*";
        //    Regex rx = new Regex(sRegex, RegexOptions.Compiled | RegexOptions.IgnoreCase);
        //    string[] sFiles = Directory.GetFiles(dir, sFileSearch);
        //    int iMax = 0;
        //    foreach (string sFile in sFiles)
        //    {
        //        match = rx.Match(zPath.GetFileName(sFile));
        //        if (!match.Success) continue;
        //        int iIndex = int.Parse(match.Groups[1].Value);
        //        if (iMax < iIndex) iMax = iIndex;
        //    }
        //    return iMax;
        //}

        //public static int GetLastDirectoryIndex(string dir, string dirname)
        //{
        //    if (!Directory.Exists(dir))
        //    {
        //        Directory.CreateDirectory(dir);
        //        return 0;
        //    }
        //    string sRegex;
        //    string sDirSearch;
        //    Match match = __rgGetNewIndexedFileName.Match(dirname);
        //    if (!match.Success)
        //    {
        //        sDirSearch = "*_*" + dirname;
        //        sRegex = "^([0-9]+)_" + dirname;
        //    }
        //    else
        //    {
        //        sRegex = "^" + match.zReplace(dirname, "([0-9]+)");
        //        sDirSearch = match.zReplace(dirname, "*");
        //        if (!sDirSearch.EndsWith("*")) sDirSearch += "*";
        //    }

        //    Regex rx = new Regex(sRegex, RegexOptions.Compiled | RegexOptions.IgnoreCase);
        //    string[] sFiles = Directory.GetDirectories(dir, sDirSearch);
        //    int iMax = 0;
        //    foreach (string sFile in sFiles)
        //    {
        //        match = rx.Match(zPath.GetFileName(sFile));
        //        if (!match.Success) continue;
        //        int iIndex = int.Parse(match.Groups[1].Value);
        //        if (iMax < iIndex) iMax = iIndex;
        //    }
        //    return iMax;
        //}

        public static string GetNewIndexedFileName(string dir, string filename = null, int indexLength = 0, TextIndexOption option = TextIndexOption.NumberBefore)
        {
            if (dir == null)
                return null;

            int maxIndexLength;
            int index = GetLastFileNameIndex(dir, filename, option, out maxIndexLength) + 1;
            if (indexLength == 0)
                indexLength = maxIndexLength;
            if (indexLength == 0)
                indexLength = 4;
            string indexedFile = index.ToString();
            int l = indexedFile.Length;
            if (l < indexLength)
                indexedFile = new string('0', indexLength - l) + indexedFile;
            return zPath.Combine(dir, indexedFile + filename);
        }
Ejemplo n.º 7
0
        public static int GetLastFileNameIndex(string dir, string filename = null, TextIndexOption option = TextIndexOption.NumberBefore)
        {
            int maxIndexLength;

            return(GetLastFileNameIndex(dir, filename, option, out maxIndexLength));
        }
Ejemplo n.º 8
0
        //public static string GetNewIndexedFileName(string path)
        //{
        //    int index; string fileMask;
        //    return GetNewIndexedFileName(path, out index, out fileMask);
        //}

        //public static string GetNewIndexedFileName(string path, out int index, out string fileMask)
        //{
        //    index = 0;
        //    fileMask = null;
        //    if (path == null) return null;

        //    // zPath.GetDirectoryName(path);
        //    // exception générée et capturée par le debugger mais qui n'apparait pas à l'exécution
        //    // System.NotSupportedException "The given path's format is not supported."
        //    // path = "C:\\pib\\prog\\tools\\runsource\\run\\RunSource_{0:00000}.*"
        //    string dir = zPath.GetDirectoryName(path);
        //    int l = dir.Length + 1;
        //    string file = path.Substring(l, path.Length - l);

        //    string ext = null;
        //    int i = file.LastIndexOf('.');
        //    if (i != -1)
        //    {
        //        ext = file.Substring(i, file.Length - i);
        //        file = file.Substring(0, i);
        //    }

        //    if (!__rgGetNewIndexedFileName.IsMatch(file)) file = "{0:0000}_" + file;
        //    index = GetLastFileNameIndex(dir, file, ext) + 1;

        //    fileMask = file;
        //    if (ext != null) fileMask += ext;
        //    fileMask = zPath.Combine(dir, fileMask);
        //    return string.Format(fileMask, index);
        //}

        //public static string GetNewIndexedDirectory(string path)
        //{
        //    if (path == null) return null;

        //    string dir = zPath.GetDirectoryName(path);
        //    int l = dir.Length + 1;
        //    string dirname = path.Substring(l, path.Length - l);

        //    if (!__rgGetNewIndexedFileName.IsMatch(dirname))
        //        dirname = "{0:0000}_" + dirname;
        //    int iIndex = GetLastDirectoryIndex(dir, dirname) + 1;
        //    return zPath.Combine(dir, string.Format(dirname, iIndex));
        //}

        //public static int GetLastFileNameIndex(string dir, string file, string ext)
        //{
        //    if (!Directory.Exists(dir))
        //    {
        //        Directory.CreateDirectory(dir);
        //        return 0;
        //    }
        //    string sRegex;
        //    string sFileSearch;
        //    Match match = __rgGetNewIndexedFileName.Match(file);
        //    if (!match.Success)
        //    {
        //        sFileSearch = "*_*" + file;
        //        sRegex = "^([0-9]+)_" + file;
        //    }
        //    else
        //    {
        //        sRegex = "^" + match.zReplace(file, "([0-9]+)");
        //        sFileSearch = match.zReplace(file, "*");
        //        if (!sFileSearch.EndsWith("*")) sFileSearch += "*";
        //    }
        //    if (ext != null && ext != "")
        //        sFileSearch += ext;
        //    else
        //        sFileSearch += ".*";
        //    Regex rx = new Regex(sRegex, RegexOptions.Compiled | RegexOptions.IgnoreCase);
        //    string[] sFiles = Directory.GetFiles(dir, sFileSearch);
        //    int iMax = 0;
        //    foreach (string sFile in sFiles)
        //    {
        //        match = rx.Match(zPath.GetFileName(sFile));
        //        if (!match.Success) continue;
        //        int iIndex = int.Parse(match.Groups[1].Value);
        //        if (iMax < iIndex) iMax = iIndex;
        //    }
        //    return iMax;
        //}

        //public static int GetLastDirectoryIndex(string dir, string dirname)
        //{
        //    if (!Directory.Exists(dir))
        //    {
        //        Directory.CreateDirectory(dir);
        //        return 0;
        //    }
        //    string sRegex;
        //    string sDirSearch;
        //    Match match = __rgGetNewIndexedFileName.Match(dirname);
        //    if (!match.Success)
        //    {
        //        sDirSearch = "*_*" + dirname;
        //        sRegex = "^([0-9]+)_" + dirname;
        //    }
        //    else
        //    {
        //        sRegex = "^" + match.zReplace(dirname, "([0-9]+)");
        //        sDirSearch = match.zReplace(dirname, "*");
        //        if (!sDirSearch.EndsWith("*")) sDirSearch += "*";
        //    }

        //    Regex rx = new Regex(sRegex, RegexOptions.Compiled | RegexOptions.IgnoreCase);
        //    string[] sFiles = Directory.GetDirectories(dir, sDirSearch);
        //    int iMax = 0;
        //    foreach (string sFile in sFiles)
        //    {
        //        match = rx.Match(zPath.GetFileName(sFile));
        //        if (!match.Success) continue;
        //        int iIndex = int.Parse(match.Groups[1].Value);
        //        if (iMax < iIndex) iMax = iIndex;
        //    }
        //    return iMax;
        //}

        public static string GetNewIndexedFileName(string dir, string filename = null, int indexLength = 0, TextIndexOption option = TextIndexOption.NumberBefore)
        {
            if (dir == null)
            {
                return(null);
            }

            int maxIndexLength;
            int index = GetLastFileNameIndex(dir, filename, option, out maxIndexLength) + 1;

            if (indexLength == 0)
            {
                indexLength = maxIndexLength;
            }
            if (indexLength == 0)
            {
                indexLength = 4;
            }
            string indexedFile = index.ToString();
            int    l           = indexedFile.Length;

            if (l < indexLength)
            {
                indexedFile = new string('0', indexLength - l) + indexedFile;
            }
            return(zPath.Combine(dir, indexedFile + filename));
        }
Ejemplo n.º 9
0
        public static string GetNewIndexedDirectory(string dir, string dirname = null, int indexLength = 0, TextIndexOption option = TextIndexOption.NumberBefore)
        {
            if (dir == null)
            {
                return(null);
            }

            int maxIndexLength;
            int index = GetLastDirectoryIndex(dir, dirname, option, out maxIndexLength) + 1;

            if (indexLength == 0)
            {
                indexLength = maxIndexLength;
            }
            if (indexLength == 0)
            {
                indexLength = 4;
            }
            string indexedDirectory = index.ToString();
            int    l = indexedDirectory.Length;

            if (l < indexLength)
            {
                indexedDirectory = new string('0', indexLength - l) + indexedDirectory;
            }
            return(zPath.Combine(dir, indexedDirectory + dirname));
        }
Ejemplo n.º 10
0
        public static string GetNewIndexedDirectory(string dir, string dirname = null, int indexLength = 0, TextIndexOption option = TextIndexOption.NumberBefore)
        {
            if (dir == null)
                return null;

            int maxIndexLength;
            int index = GetLastDirectoryIndex(dir, dirname, option, out maxIndexLength) + 1;
            if (indexLength == 0)
                indexLength = maxIndexLength;
            if (indexLength == 0)
                indexLength = 4;
            string indexedDirectory = index.ToString();
            int l = indexedDirectory.Length;
            if (l < indexLength)
            {
                indexedDirectory = new string('0', indexLength - l) + indexedDirectory;
            }
            return zPath.Combine(dir, indexedDirectory + dirname);
        }