Exemple #1
0
        public void ReplaceName(string sourcePath, string sourceName, string targetName)
        {
            StringReplacePattern pattern = new StringReplacePattern(sourceName, targetName);

            if (!Directory.Exists(sourcePath))
            {
                return;
            }

            MapSubDirectory(sourcePath, sourceName, targetName);

            foreach (var file in Directory.GetFiles(sourcePath).Where(f => Fit(f, ".cs", ".sln", ".csproj", ".cshtml", ".config", ".xml", ".txt", ".js", ".asax", ".bat", ".json", ".sql", ".tt", ".edmx", ".html")))
            {
                long length = new System.IO.FileInfo(file).Length;

                if (length > 0)
                {
                    var content = File.ReadAllText(file, GetFileEncodeType(file));

                    string targetContent;

                    if (pattern.MatchAndReplace(content, out targetContent))
                    {
                        File.WriteAllText(file, targetContent, Encoding.UTF8);
                    }

                    //if (content.Contains(sourceName))
                    //{
                    //    content = content.Replace(sourceName, targetName);

                    //    File.WriteAllText(file, content, Encoding.UTF8);
                    //}
                }
            }
        }
Exemple #2
0
        public void ReplaceFileName(string sourcePath, string sourceName, string targetName)
        {
            var pattern = new StringReplacePattern(sourceName, targetName);

            if (!Directory.Exists(sourcePath))
            {
                return;
            }

            MapSubDirectory(sourcePath, sourceName, targetName);

            foreach (var file in Directory.GetFiles(sourcePath))
            {
                string replace = null;
                try
                {
                    var shortName = Path.GetFileName(file);
                    if (shortName == null)
                    {
                        continue;
                    }

                    if (pattern.MatchAndReplace(file, out replace))
                    {
                        ChangeFileName(file, replace);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("{0}-{1}:{2}", sourceName, replace, file), ex);
                }



                //if (shortName.Contains(sourceName))
                //{
                //    var targetPath = file.Replace(sourceName, targetName);

                //    ChangeFileName(file, targetPath);
                //}
            }
        }
Exemple #3
0
        public void ReplaceDirectoryName(string sourcePath, string sourceName, string targetName)
        {
            StringReplacePattern pattern = new StringReplacePattern(sourceName, targetName);

            if (!Directory.Exists(sourcePath))
            {
                return;
            }


            ReplaceSubDirectory(sourcePath, sourceName, targetName);

            var shortName = Path.GetFileName(sourcePath);

            if (shortName == null)
            {
                return;
            }

            string targetDirectoryName;

            if (pattern.MatchAndReplace(shortName, out targetDirectoryName))
            {
                var root = Path.GetDirectoryName(sourcePath);

                ChangeDirectoryName(sourcePath, Path.Combine(root, targetDirectoryName));
            }

            //if (shortName.Contains(sourceName))
            //{
            //    var root = Path.GetDirectoryName(sourcePath);

            //    var shortDirectoryName = Path.GetFileName(sourcePath);
            //    var targetDirectoryName = shortDirectoryName.Replace(sourceName, targetName);
            //    if (sourcePath.Contains("Localization"))
            //    {
            //        int i = 2;
            //    }
            //    ChangeDirectoryName(sourcePath, Path.Combine(root,targetDirectoryName));
            //}
        }