当前位置: 首页>>代码示例>>C#>>正文


C# FileInfo.Replace方法代码示例

本文整理汇总了C#中System.IO.FileInfo.Replace方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.Replace方法的具体用法?C# FileInfo.Replace怎么用?C# FileInfo.Replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.FileInfo的用法示例。


在下文中一共展示了FileInfo.Replace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateDestFileName

        private string GenerateDestFileName(JToken title)
        {
            string destFile = title.ToString();
            var index1 = destFile.IndexOf('(');
            var index2 = destFile.IndexOf(')', index1);

            destFile = destFile.Substring(index1 + 1, index2 - index1-1);

            return destFile.Replace(" ", string.Empty) + ".json";
        }
开发者ID:flyeven,项目名称:AngJobs,代码行数:10,代码来源:HackerNews.cs

示例2: getContents

        public ModFile[] getContents()
        {
            string[] modStringFiles = Directory.GetFiles(this.folderPath);
            ModFile[] modFiles = new ModFile[modStringFiles.Length];

            for (int i = 0; i < modStringFiles.Length; i++)
            {
                string modFileName = new FileInfo(modStringFiles[i]).Name.ToLower();
                string modFolderName = new DirectoryInfo(this.folderPath).Name.ToLower();
                modFiles[i] = new ModFile(modFolderName, modFileName.Replace(modFolderName, string.Empty));
            }
            return modFiles;
        }
开发者ID:Tommsy64,项目名称:Solder-Mod-Packager,代码行数:13,代码来源:ModFolder.cs

示例3: SetupDefaultPackage

 private static void SetupDefaultPackage()
 {
     string FileContent = new FileInfo("..\\..\\..\\BatmanPackages\\Batman.MVC.Default.nuspec").Read();
     string CurrentVersion = Regex.Match(FileContent, "<version>(?<VersionNumber>.*)</version>").Groups["VersionNumber"].Value;
     foreach (Match TempMatch in Regex.Matches(FileContent, @"<dependency id=""(?<Dependency>[^""]*)"" version=""(?<VersionNumber>[^""]*)"" />"))
     {
         if (TempMatch.Value.Contains("Batman"))
         {
             FileContent = FileContent.Replace(TempMatch.Value, "<dependency id=\"" + TempMatch.Groups["Dependency"] + "\" version=\"[" + CurrentVersion + "]\" />");
         }
     }
     new FileInfo("..\\..\\..\\BatmanPackages\\Batman.MVC.Default.nuspec").Save(FileContent);
 }
开发者ID:JaCraig,项目名称:Batman,代码行数:13,代码来源:Program.cs

示例4: AgDocumentView

        public AgDocumentView()
        {
            InitializeComponent();

            string dir = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName;
            ContentArea.Source = new Uri(string.Format("file://{0}/AgHost/AgHost.html", dir.Replace("\\", "/")));

            KaxamlInfo.Frame = null;

            string schemafile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(App.StartupPath + "\\"), Kaxaml.Properties.Settings.Default.AgSchema);
            XmlCompletionDataProvider.LoadSchema(schemafile);

            Parse();
        }
开发者ID:punker76,项目名称:kaxaml,代码行数:14,代码来源:AgDocumentView.xaml.cs

示例5: Main

        static void Main( string[] args )
        {
            var outputDirPath = System.IO.Path.Combine( Application.StartupPath, "Output" );
            if( !Directory.Exists( outputDirPath ) )
            {
                try
                {
                    Directory.CreateDirectory( outputDirPath );
                }
                catch( Exception ex )
                {
                    Console.WriteLine( ex.Message );
                    Console.ReadKey();
                    return;
                }
            }
            foreach( var fn in Directory.GetFiles( Application.StartupPath, "PacketTemplate_*.dll" ) )
            {
                var asm = Assembly.LoadFile( fn );
                var t = Helpers.GetTemplate( asm );
                var shortfn = new FileInfo( fn ).Name;
                shortfn = shortfn.Substring( 0, shortfn.LastIndexOf( '.' ) );
                var path = System.IO.Path.Combine( outputDirPath, shortfn.Replace( ".", "_" ) );
                if( !Directory.Exists( path ) )
                {
                    try
                    {
                        Directory.CreateDirectory( path );
                    }
                    catch( Exception ex )
                    {
                        Console.WriteLine( ex.Message );
                        Console.ReadKey();
                        return;
                    }
                }

                var rtv = GenCPP.Gen( t, path, shortfn.Substring( "PacketTemplate_".Length ) );
                if( rtv != "" )
                {
                    Console.WriteLine( rtv );
                    Console.ReadKey();
                    return;
                }
            }
        }
开发者ID:whuthj,项目名称:69net,代码行数:46,代码来源:Program.cs

示例6: RollBack

 public void RollBack(string catalog, string dir1)
 {
     Console.WriteLine("\nВведите дату и время, на которые должен быть осуществлен откат \nВарианты:\n");
     DirectoryInfo FilesTxt = new DirectoryInfo(dir1);
     foreach (var item in FilesTxt.GetFiles("*.txt", SearchOption.AllDirectories))
     {
         Console.WriteLine(" - " + item.LastWriteTime.ToString().Replace(':', '.'));
     }
     string data = Console.ReadLine();
     DirectoryInfo dir2 = Directory.CreateDirectory(@"C:\zzz\rezerv\");
     foreach (var item in FilesTxt.GetFiles("*.txt", SearchOption.AllDirectories))
     {
         if (data == item.LastWriteTime.ToString().Replace(':', '.'))
         {
             string path = dir1 + item.Name;
             FileInfo fi1 = new FileInfo(path);
             fi1.Replace(catalog + item.Name.Substring(20), dir2 + "rezerv" + item.Name);
             Console.WriteLine("Текстовый файл \"{0}\" принял вид, соответсвтующий указанному времени", item.Name);
         }
     }
 }
开发者ID:Diana04,项目名称:Ishmatova_Diana,代码行数:21,代码来源:WorkWithFileSystem.cs

示例7: AddToProject

        public void AddToProject(AddToProjectRequest request)
        {
            if (request.FileName == null || !request.FileName.EndsWith(".cs"))
            {
                return;
            }

            var relativeProject = _solution.ProjectContainingFile(request.FileName);

            if (relativeProject == null || relativeProject is OrphanProject)
            {
                throw new ProjectNotFoundException(string.Format("Unable to find project relative to file {0}", request.FileName));
            }

            var project = relativeProject.AsXml();

            var requestFile = new FileInfo(request.FileName).FullName;
            var projectDirectory = new FileInfo(relativeProject.FileName).Directory;

            var relativeFileName = requestFile.Replace(projectDirectory.FullName, "").Replace("/", @"\").Substring(1);

            var compilationNodes = project.Element(_msBuildNameSpace + "Project")
                                          .Elements(_msBuildNameSpace + "ItemGroup")
                                          .Elements(_msBuildNameSpace + "Compile").ToList();

            var fileAlreadyInProject = compilationNodes.Any(n => n.Attribute("Include").Value.Equals(relativeFileName, StringComparison.InvariantCultureIgnoreCase));

            if (!fileAlreadyInProject)
            {
                var compilationNodeParent = compilationNodes.First().Parent;

                var newFileElement = new XElement(_msBuildNameSpace + "Compile", new XAttribute("Include", relativeFileName));

                compilationNodeParent.Add(newFileElement);
                
                relativeProject.Save(project);
            }
        }
开发者ID:dykim07,项目名称:vim-ide,代码行数:38,代码来源:AddToProjectHandler.cs

示例8: GetLookupType

 private static TypeInfo GetLookupType(string testFileDir)
 {
     var fileName = new FileInfo(testFileDir).Name;
     fileName = fileName.Replace(".cs", "");
     return fileName;
 }
开发者ID:chrisjowen,项目名称:ResolveIt,代码行数:6,代码来源:Program.cs

示例9: GetTableNameFromFilePath

 private string GetTableNameFromFilePath(string filePath)
 {
     var fileName = new FileInfo(filePath).Name;
     return "dbo." + fileName.Replace(".txt", "");
 }
开发者ID:svlcode,项目名称:PowerGenerator,代码行数:5,代码来源:MainForm.cs

示例10: ordernarArchivos

 private string[] ordernarArchivos(string[] archivos)
 {
     int[] names = new int[archivos.Length];
     Dictionary<int, string> Name_Path = new Dictionary<int, string>();
     string fname;
     for (int i = 0; i < archivos.Length; i++)
     {
         fname = new FileInfo(archivos[i]).Name;
         names[i] = int.Parse(fname.Replace(".pdf", ""));
         Name_Path.Add(names[i], archivos[i]);
     }
     Array.Sort(names);
     for (int i = 0; i < names.Length; i++)
     {
         archivos[i] = Name_Path[names[i]];
     }
     return archivos;
 }
开发者ID:GeMaths,项目名称:etiquetasPMM,代码行数:18,代码来源:EtiquetasPedidosMostrador.cs

示例11: IsReady2


//.........这里部分代码省略.........
                if (k < bac.CheckBoxArr.Length - 1)
                {
                    Array.Resize(ref currentLineBubbles, 0);
                    currentLine = bubble2.point.Y;
                    RecognitionTools.AppendOutput(ref totalOutput, indexAnswersPosition, currentLine.ToString(), indexAnswersPosition, indexOfFirstBubble);
                    subStrSet = new int[areas[bubble2.areaNumber].subLinesAmount];
                    k--;
                }
            }
            try
            {
                string[] str = totalOutput[indexAnswersPosition - 1] as string[];
                int first = Convert.ToInt32(str[0]);
                if (first != indexOfFirstQuestion)
                {
                    for (int k = 0; k < str.Length; k++)
                    {
                        str[k] = (indexOfFirstQuestion + k).ToString();
                    }
                    totalOutput[indexAnswersPosition - 1] = str;
                }
            }
            catch (Exception) { }
            var direct = Defaults.ManualSuccessFolder;
            foreach (KeyValuePair<int, string> item in outputFileValues)
            {
                if (item.Key > totalOutput.Length)
                {
                    Array.Resize(ref totalOutput, item.Key);
                }
                totalOutput[item.Key - 1] = item.Value;
            }
            for (int num = 0; num < regions.regions.Length; num++)
            {
                string type = regions.regions[num].type;
                bool? active = regions.regions[num].active;
                string name = regions.regions[num].name;

                if (active == false || type == "marker" || name == "sheetIdentifier")
                {
                    continue;
                }
                regionOutputPosition = regions.regions[num].outputPosition;
                if (regionOutputPosition > 0)
                {
                    foreach (var item in barCodeControls)
                    {
                        if (item.Name == name)
                        {
                            headersValues[regionOutputPosition - 1] = item.barCodeValue;
                            totalOutput[regionOutputPosition - 1] = item.barCodeValue;
                            break;
                        }
                    }
                }
            }
            string outputFileNameFormat = "";
            if (regions != null)
            {
                outputFileNameFormat = regions.outputFileNameFormat;
            }
            for (int k = 0; k < allBarCodeNames.Length; k++)
            {
                int index = Array.IndexOf(headers, allBarCodeNames[k]);
                if (index >= 0)
                {
                    if (outputFileValues.Keys.Contains(k))
                    {
                        allBarCodeValues[k] = outputFileValues[k];
                    }
                }
                outputFileNameFormat = outputFileNameFormat.Replace
                    ("{" + allBarCodeNames[k] + "}", allBarCodeValues[k]);
            }
            var destFileName = direct + "\\" + outputFileNameFormat + ".csv";
            Utils.CreateDirectory(direct);
            destFileName = destFileName.Replace(@"\\", @"\");
            destFileName = Utils.GetNextFileName(destFileName);

            string destFileNameTiff;
            destFileNameTiff = Utils.GetNextFileName(direct + "\\" + outputFileNameFormat + ".tiff");
            //b.Save(destFileNameTiff, ImageFormat.Tiff);
            destFileNameTiff = destFileNameTiff.Replace(@"\\", @"\");
            repeat: try
            {
                File.Move(FileName, destFileNameTiff);
            }
            catch (Exception ex)
            {
                goto repeat;
            }
            var currentFileName = destFileNameTiff;
            var fi = new FileInfo(FileName);
            var fn1 = new FileInfo(FileName).Name;
            var fn2 = fn1.Replace(new FileInfo(FileName).Extension, ".audit");
            Utils.DeleteFile(Defaults.TempEdFolder + "\\" + fn2);
            StringBuilder[] sb = new StringBuilder[1];
            RecognitionTools.WriteCsv(false, destFileName, barCodesPrompt, sb, totalOutput
                 , answersPosition, indexAnswersPosition, additionalOutputData, barCodes);
        }
开发者ID:ifidakov,项目名称:trunk,代码行数:101,代码来源:Recognize.cs

示例12: Replace1_Source_FileNotFound

		public void Replace1_Source_FileNotFound ()
		{
			string path1 = TempFolder + DSC + "FIT.Replace.Source.Test";
			string path2 = TempFolder + DSC + "FIT.Replace.Dest.Test";
			DeleteFile (path2);

			try {
				try {
					File.Create (path2).Close ();
					FileInfo info = new FileInfo (path1);
					info.Replace (path2, null);
					Assert.Fail ("#1");
				} catch (FileNotFoundException ex) {
					Assert.AreEqual (typeof (FileNotFoundException), ex.GetType (), "#2");
					Assert.IsNull (ex.InnerException, "#3");
					Assert.IsNotNull (ex.Message, "#4");
				}
			} finally {
				DeleteFile (path2);			
			}		
		}
开发者ID:TheMetalMage,项目名称:mono,代码行数:21,代码来源:FileInfoTest.cs

示例13: CompressGifs

        private static void CompressGifs(string sourceDirectory)
        {
            string tempFilePath = Path.GetTempFileName();
            File.Delete(tempFilePath);
            using (var process = new Process())
            {
                process.StartInfo.CreateNoWindow = true;
                process.StartInfo.UseShellExecute = false;

                int gifsOptimized = 0;
                process.StartInfo.FileName = Path.Combine(Environment.CurrentDirectory, "gifsicle.exe");
                if (!File.Exists(process.StartInfo.FileName))
                {
                    Console.WriteLine("Missing gifsicle.exe in current directory.");
                    return;
                }
                Console.WriteLine();
                foreach (var sourceFilePath in Directory.EnumerateFiles(sourceDirectory, "*.gif", SearchOption.AllDirectories))
                {
                    string trimmedSourcePath = sourceFilePath.Replace(sourceDirectory, "");
                    ConsoleReplacePreviousLine("Optimizing " + trimmedSourcePath);
                    bool optimized = false;
                    bool optimizedOnPass;
                    do
                    {
                        optimizedOnPass = false;
                        FileInfo sourceFile = new FileInfo(sourceFilePath);
                        sourceFile.CopyTo(tempFilePath, true);
                        process.StartInfo.Arguments =
                            "-b -O3 --no-comments --no-extensions --no-names \"" + tempFilePath + "\"";
                        process.Start();
                        process.WaitForExit();
                        if (process.ExitCode != 0)
                        {
                            Console.WriteLine("gifsicle exited with code " + process.ExitCode + " for " + trimmedSourcePath);
                            Console.WriteLine();
                        }
                        else
                        {
                            FileInfo tempFile = new FileInfo(tempFilePath);
                            if (tempFile.Length < sourceFile.Length)
                            {
                                Console.WriteLine(
                                    "Optimized " + sourceFile.Length + " to " + tempFile.Length + " for " + trimmedSourcePath);
                                RetryActionWithDelay(() => tempFile.Replace(sourceFilePath, null), 3, TimeSpan.FromSeconds(0.5));
                                optimizedOnPass = true;
                                optimized = true;
                            }
                        }
                    } while (optimizedOnPass);
                    if (optimized)
                    {
                        Console.WriteLine();
                        gifsOptimized++;
                    }
                }
                if (File.Exists(tempFilePath))
                    File.Delete(tempFilePath);
                ConsoleReplacePreviousLine(gifsOptimized + " GIFs optimized.");
            }
        }
开发者ID:TobleMiner,项目名称:Desktop-Ponies,代码行数:61,代码来源:Program.cs

示例14: Replace1_DestFileName_WhiteSpace

		public void Replace1_DestFileName_WhiteSpace ()
		{
			string path1 = TempFolder + DSC + "FIT.Replace.Source.Test";
			DeleteFile (path1);
			try {
				try {
					File.Create (path1).Close ();
					FileInfo info = new FileInfo (path1);
					info.Replace ("     ", null);
					Assert.Fail ("#1");
				} catch (ArgumentException ex) {
					Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
					Assert.IsNull (ex.InnerException, "#3");
					Assert.IsNotNull (ex.Message, "#4");
				}
			} finally {
				DeleteFile (path1);
			}
		}
开发者ID:TheMetalMage,项目名称:mono,代码行数:19,代码来源:FileInfoTest.cs

示例15: TestFilePath

        public void TestFilePath()
        {
            var q = _fileInfo.FilePath;

            var exp = new FileInfo(_testFilePath1.FullName).FullName;

            Assert.AreEqual(exp.Replace("\\", "/"), q);
        }
开发者ID:nanox,项目名称:QtSharp,代码行数:8,代码来源:QFileInfoTests.cs


注:本文中的System.IO.FileInfo.Replace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。