本文整理汇总了C#中System.IO.FileInfo.Rename方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.Rename方法的具体用法?C# FileInfo.Rename怎么用?C# FileInfo.Rename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileInfo
的用法示例。
在下文中一共展示了FileInfo.Rename方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Rename
public void Rename()
{
// Type
var workingDirectory = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "System_IO_FileInfo_Rename"));
workingDirectory.EnsureDirectoryExists();
workingDirectory.Clear();
var @this = new FileInfo(Path.Combine(workingDirectory.FullName, "Examples_System_IO_FileInfo_Rename.txt"));
var @thisNewFile = new FileInfo(Path.Combine(workingDirectory.FullName, "Examples_System_IO_FileInfo_Rename2.cs"));
bool result1 = @thisNewFile.Exists;
// Intialization
using (FileStream stream = @this.Create())
{
}
// Examples
@this.Rename("Examples_System_IO_FileInfo_Rename2.cs");
// Unit Test
@thisNewFile = new FileInfo(Path.Combine(workingDirectory.FullName, "Examples_System_IO_FileInfo_Rename2.cs"));
bool result2 = @thisNewFile.Exists;
Assert.IsFalse(result1);
Assert.IsTrue(result2);
}
示例2: RenameFile
public void RenameFile()
{
String path = @"c:\temp\setup.txt";
FileInfo file = new FileInfo(path);
Assert.True(file.Exists);
FileInfo newFile = file.Rename("abc.txt");
Assert.False(file.Exists);
Assert.True(newFile.Exists);
}
示例3: CanRenameAFile
public void CanRenameAFile()
{
var file = new FileInfo(@"C:\temp\Test.txt");
file.Rename("Test2.txt");
}
示例4: SaveButton_Click
//.........这里部分代码省略.........
contents = Regex.Replace(contents, Scores["SCORE_KILLASSIST_DRIVER"][1], "SCORE_KILLASSIST_DRIVER = " + DriverKA.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["SCORE_KILLASSIST_PASSENGER"][1], "SCORE_KILLASSIST_PASSENGER = " + PassangerKA.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["SCORE_KILLASSIST_TARGETER"][1], "SCORE_KILLASSIST_TARGETER = " + TargeterKA.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["SCORE_KILLASSIST_DAMAGE"][1], "SCORE_KILLASSIST_DAMAGE = " + DamageAssist.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["SCORE_HEAL"][1], "SCORE_HEAL = " + GiveHealth.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["SCORE_GIVEAMMO"][1], "SCORE_GIVEAMMO = " + GiveAmmo.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["SCORE_REPAIR"][1], "SCORE_REPAIR = " + VehicleRepair.Value, RegexOptions.Multiline);
// Bots
contents = Regex.Replace(contents, Scores["AI_SCORE_KILL"][1], "AI_SCORE_KILL = " + AiKillScore.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["AI_SCORE_TEAMKILL"][1], "AI_SCORE_TEAMKILL = " + AiTeamKillScore.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["AI_SCORE_SUICIDE"][1], "AI_SCORE_SUICIDE = " + AiSuicideScore.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["AI_SCORE_REVIVE"][1], "AI_SCORE_REVIVE = " + AiReviveScore.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["AI_SCORE_TEAMDAMAGE"][1], "AI_SCORE_TEAMDAMAGE = " + AiTeamDamage.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["AI_SCORE_TEAMVEHICLEDAMAGE"][1], "AI_SCORE_TEAMVEHICLEDAMAGE = " + AiTeamVehicleDamage.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["AI_SCORE_DESTROYREMOTECONTROLLED"][1], "AI_SCORE_DESTROYREMOTECONTROLLED = " + AiDestroyEnemyAsset.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["AI_SCORE_KILLASSIST_DRIVER"][1], "AI_SCORE_KILLASSIST_DRIVER = " + AiDriverKA.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["AI_SCORE_KILLASSIST_PASSENGER"][1], "AI_SCORE_KILLASSIST_PASSENGER = " + AiPassangerKA.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["AI_SCORE_KILLASSIST_TARGETER"][1], "AI_SCORE_KILLASSIST_TARGETER = " + AiTargeterKA.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["AI_SCORE_KILLASSIST_DAMAGE"][1], "AI_SCORE_KILLASSIST_DAMAGE = " + AiDamageAssist.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["AI_SCORE_HEAL"][1], "AI_SCORE_HEAL = " + AiGiveHealth.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["AI_SCORE_GIVEAMMO"][1], "AI_SCORE_GIVEAMMO = " + AiGiveAmmo.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["AI_SCORE_REPAIR"][1], "AI_SCORE_REPAIR = " + AiVehicleRepair.Value, RegexOptions.Multiline);
// Replenish
contents = Regex.Replace(contents, Scores["REPAIR_POINT_LIMIT"][1], "REPAIR_POINT_LIMIT = " + RepairPointLimit.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["HEAL_POINT_LIMIT"][1], "HEAL_POINT_LIMIT = " + HealPointLimit.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["GIVEAMMO_POINT_LIMIT"][1], "GIVEAMMO_POINT_LIMIT = " + AmmoPointLimit.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["TEAMDAMAGE_POINT_LIMIT"][1], "TEAMDAMAGE_POINT_LIMIT = " + TeamDamageLimit.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["TEAMVEHICLEDAMAGE_POINT_LIMIT"][1], "TEAMVEHICLEDAMAGE_POINT_LIMIT = " + TeamVDamageLimit.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, Scores["REPLENISH_POINT_MIN_INTERVAL"][1], "REPLENISH_POINT_MIN_INTERVAL = " + ReplenishInterval.Value, RegexOptions.Multiline);
// Save File
using (Stream Str = ScoringCommonFile.Open(FileMode.Truncate, FileAccess.Write))
using (StreamWriter Wtr = new StreamWriter(Str))
{
Wtr.Write(contents);
Wtr.Flush();
}
// ========================================== Scoring Conquest
// Get curent file contents
using (Stream Str = ScoringConqFile.OpenRead())
using (StreamReader Rdr = new StreamReader(Str))
contents = Rdr.ReadToEnd();
// Do Replacements
contents = Regex.Replace(contents, ConqScores["SCORE_CAPTURE"][1], "SCORE_CAPTURE = " + ConqFlagCapture.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, ConqScores["SCORE_CAPTUREASSIST"][1], "SCORE_CAPTUREASSIST = " + ConqFlagCaptureAsst.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, ConqScores["SCORE_NEUTRALIZE"][1], "SCORE_NEUTRALIZE = " + ConqFlagNeutralize.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, ConqScores["SCORE_NEUTRALIZEASSIST"][1], "SCORE_NEUTRALIZEASSIST = " + ConqFlagNeutralizeAsst.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, ConqScores["SCORE_DEFEND"][1], "SCORE_DEFEND = " + ConqDefendFlag.Value, RegexOptions.Multiline);
// Bots
contents = Regex.Replace(contents, ConqScores["AI_SCORE_CAPTURE"][1], "AI_SCORE_CAPTURE = " + AiCqFlagCapture.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, ConqScores["AI_SCORE_CAPTUREASSIST"][1], "AI_SCORE_CAPTUREASSIST = " + AiCqFlagCaptureAsst.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, ConqScores["AI_SCORE_NEUTRALIZE"][1], "AI_SCORE_NEUTRALIZE = " + AiCqFlagNeutralize.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, ConqScores["AI_SCORE_NEUTRALIZEASSIST"][1], "AI_SCORE_NEUTRALIZEASSIST = " + AiCqFlagNeutralizeAsst.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, ConqScores["AI_SCORE_DEFEND"][1], "AI_SCORE_DEFEND = " + AiCqDefendFlag.Value, RegexOptions.Multiline);
// Save File
using (Stream Str = ScoringConqFile.Open(FileMode.Truncate, FileAccess.Write))
using (StreamWriter Wtr = new StreamWriter(Str))
{
Wtr.Write(contents);
Wtr.Flush();
}
// ========================================== Scoring Coop
// Get current file contents
using (Stream Str = ScoringCoopFile.OpenRead())
using (StreamReader Rdr = new StreamReader(Str))
contents = Rdr.ReadToEnd();
// Do Replacements
contents = Regex.Replace(contents, CoopScores["SCORE_CAPTURE"][1], "SCORE_CAPTURE = " + CoopFlagCapture.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, CoopScores["SCORE_CAPTUREASSIST"][1], "SCORE_CAPTUREASSIST = " + CoopFlagCaptureAsst.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, CoopScores["SCORE_NEUTRALIZE"][1], "SCORE_NEUTRALIZE = " + CoopFlagNeutralize.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, CoopScores["SCORE_NEUTRALIZEASSIST"][1], "SCORE_NEUTRALIZEASSIST = " + CoopFlagNeutralizeAsst.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, CoopScores["SCORE_DEFEND"][1], "SCORE_DEFEND = " + CoopDefendFlag.Value, RegexOptions.Multiline);
// Bots
contents = Regex.Replace(contents, CoopScores["AI_SCORE_CAPTURE"][1], "AI_SCORE_CAPTURE = " + AiCoopFlagCapture.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, CoopScores["AI_SCORE_CAPTUREASSIST"][1], "AI_SCORE_CAPTUREASSIST = " + AiCoopFlagCaptureAsst.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, CoopScores["AI_SCORE_NEUTRALIZE"][1], "AI_SCORE_NEUTRALIZE = " + AiCoopFlagNeutralize.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, CoopScores["AI_SCORE_NEUTRALIZEASSIST"][1], "AI_SCORE_NEUTRALIZEASSIST = " + AiCoopFlagNeutralizeAsst.Value, RegexOptions.Multiline);
contents = Regex.Replace(contents, CoopScores["AI_SCORE_DEFEND"][1], "AI_SCORE_DEFEND = " + AiCoopDefendFlag.Value, RegexOptions.Multiline);
// Save File
using (Stream Str = ScoringCoopFile.Open(FileMode.Truncate, FileAccess.Write))
using (StreamWriter Wtr = new StreamWriter(Str))
{
Wtr.Write(contents);
Wtr.Flush();
}
// Remove the ServerSettings.con file as that screws with the replenish scores
FileInfo file = new FileInfo(Path.Combine(MainForm.SelectedMod.RootPath, "Settings", "ScoreManagerSetup.con"));
if (file.Exists)
file.Rename("ScoreManagerSetup.con.bak");
// Close this form
this.Close();
}