FileInfo.Replace Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Belirtilen dosyanın içeriğini geçerli FileInfo nesne tarafından açıklanan dosyayla değiştirir, özgün dosyayı siler ve değiştirilen dosyanın yedeğini oluşturur.
Aşırı Yüklemeler
| Name | Description |
|---|---|
| Replace(String, String) |
Belirtilen dosyanın içeriğini geçerli FileInfo nesne tarafından açıklanan dosyayla değiştirir, özgün dosyayı siler ve değiştirilen dosyanın yedeğini oluşturur. |
| Replace(String, String, Boolean) |
Belirtilen dosyanın içeriğini geçerli FileInfo nesne tarafından açıklanan dosyayla değiştirir, özgün dosyayı siler ve değiştirilen dosyanın yedeğini oluşturur. Ayrıca birleştirme hatalarının yoksayılıp yoksayılmayacağını belirtir. |
Açıklamalar
Replace Bir dosyayı geçerli FileInfo nesne tarafından açıklanan dosyanın içeriğiyle hızla değiştirmeniz gerektiğinde yöntemlerini kullanın.
Replace(String, String)
- Kaynak:
- FileInfo.cs
- Kaynak:
- FileInfo.cs
- Kaynak:
- FileInfo.cs
- Kaynak:
- FileInfo.cs
- Kaynak:
- FileInfo.cs
Belirtilen dosyanın içeriğini geçerli FileInfo nesne tarafından açıklanan dosyayla değiştirir, özgün dosyayı siler ve değiştirilen dosyanın yedeğini oluşturur.
public:
System::IO::FileInfo ^ Replace(System::String ^ destinationFileName, System::String ^ destinationBackupFileName);
public System.IO.FileInfo Replace(string destinationFileName, string? destinationBackupFileName);
public System.IO.FileInfo Replace(string destinationFileName, string destinationBackupFileName);
[System.Runtime.InteropServices.ComVisible(false)]
public System.IO.FileInfo Replace(string destinationFileName, string destinationBackupFileName);
member this.Replace : string * string -> System.IO.FileInfo
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.Replace : string * string -> System.IO.FileInfo
Public Function Replace (destinationFileName As String, destinationBackupFileName As String) As FileInfo
Parametreler
- destinationFileName
- String
Geçerli dosyayla değiştirilmek üzere dosyanın adı.
- destinationBackupFileName
- String
parametresi tarafından destinationFileName açıklanan dosyanın yedeğinin oluşturulacağı dosyanın adı.
Döndürülenler
FileInfo parametresi tarafından destinationFileName açıklanan dosya hakkındaki bilgileri kapsülleyen bir nesne.
- Öznitelikler
Özel durumlar
parametresi tarafından destinationFileName açıklanan yol yasal bir biçimde değildi.
-veya-
parametresi tarafından destinationBackupFileName açıklanan yol yasal bir biçimde değildi.
destinationFileName parametresi null'dir.
Geçerli FileInfo nesne tarafından açıklanan dosya bulunamadı.
-veya-
parametresi tarafından destinationFileName açıklanan dosya bulunamadı.
Geçerli işletim sistemi Microsoft Windows NT veya üzeri değildir.
Örnekler
Aşağıdaki örnek, bir dosyayı başka bir dosyayla değiştirmek ve değiştirilen dosyanın yedeğini oluşturmak için yöntemini kullanır Replace .
using System;
using System.IO;
namespace FileSystemExample
{
class FileExample
{
public static void Main()
{
try
{
// originalFile and fileToReplace must contain the path to files that already exist in the
// file system. backUpOfFileToReplace is created during the execution of the Replace method.
string originalFile = "test.txt";
string fileToReplace = "test2.txt";
string backUpOfFileToReplace = "test2.txt.bak";
if (File.Exists(originalFile) && (File.Exists(fileToReplace)))
{
Console.WriteLine("Move the contents of " + originalFile + " into " + fileToReplace + ", delete "
+ originalFile + ", and create a backup of " + fileToReplace + ".");
// Replace the file.
ReplaceFile(originalFile, fileToReplace, backUpOfFileToReplace);
Console.WriteLine("Done");
}
else
{
Console.WriteLine("Either the file {0} or {1} doesn't " + "exist.", originalFile, fileToReplace);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadLine();
}
// Move a file into another file, delete the original, and create a backup of the replaced file.
public static void ReplaceFile(string fileToMoveAndDelete, string fileToReplace, string backupOfFileToReplace)
{
// Create a new FileInfo object.
FileInfo fInfo = new FileInfo(fileToMoveAndDelete);
// replace the file.
fInfo.Replace(fileToReplace, backupOfFileToReplace, false);
}
}
}
//Move the contents of test.txt into test2.txt, delete test.txt, and
//create a backup of test2.txt.
//Done
Imports System.IO
Module FileExample
Sub Main()
Try
' originalFile and fileToReplace must contain the path to files that already exist in the
' file system. backUpOfFileToReplace is created during the execution of the Replace method.
Dim originalFile As String = "test.xml"
Dim fileToReplace As String = "test2.xml"
Dim backUpOfFileToReplace As String = "test2.xml.bak"
If (File.Exists(originalFile) And (File.Exists(fileToReplace))) Then
Console.WriteLine("Move the contents of " + originalFile + " into " + fileToReplace + ", delete " + originalFile + ", and create a backup of " + fileToReplace + ".")
' Replace the file.
ReplaceFile(originalFile, fileToReplace, backUpOfFileToReplace)
Console.WriteLine("Done")
Else
Console.WriteLine("Either the file {0} or {1} doesn't " + "exist.", originalFile, fileToReplace)
End If
Catch e As Exception
Console.WriteLine(e.Message)
End Try
Console.ReadLine()
End Sub
' Move a file into another file, delete the original, and create a backup of the replaced file.
Sub ReplaceFile(ByVal fileToMoveAndDelete As String, ByVal fileToReplace As String, ByVal backupOfFileToReplace As String)
' Create a new FileInfo object.
Dim fInfo As New FileInfo(fileToMoveAndDelete)
' Replace the file.
fInfo.Replace(fileToReplace, backupOfFileToReplace, False)
End Sub
End Module
' Move the contents of test.txt into test2.txt, delete test.txt, and
' create a backup of test2.txt.
' Done
Açıklamalar
yöntemi, Replace belirtilen dosyanın içeriğini geçerli FileInfo nesne tarafından açıklanan dosyanın içeriğiyle değiştirir. Ayrıca değiştirilen dosyanın yedeğini de oluşturur. Son olarak, üzerine yazılan dosyayı açıklayan yeni FileInfo bir nesne döndürür.
Değiştirilen dosyanın yedeğini null oluşturmak istemiyorsanız parametresine geçindestinationBackupFileName.
Şunlara uygulanır
Replace(String, String, Boolean)
- Kaynak:
- FileInfo.cs
- Kaynak:
- FileInfo.cs
- Kaynak:
- FileInfo.cs
- Kaynak:
- FileInfo.cs
- Kaynak:
- FileInfo.cs
Belirtilen dosyanın içeriğini geçerli FileInfo nesne tarafından açıklanan dosyayla değiştirir, özgün dosyayı siler ve değiştirilen dosyanın yedeğini oluşturur. Ayrıca birleştirme hatalarının yoksayılıp yoksayılmayacağını belirtir.
public:
System::IO::FileInfo ^ Replace(System::String ^ destinationFileName, System::String ^ destinationBackupFileName, bool ignoreMetadataErrors);
public System.IO.FileInfo Replace(string destinationFileName, string? destinationBackupFileName, bool ignoreMetadataErrors);
public System.IO.FileInfo Replace(string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors);
[System.Runtime.InteropServices.ComVisible(false)]
public System.IO.FileInfo Replace(string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors);
member this.Replace : string * string * bool -> System.IO.FileInfo
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.Replace : string * string * bool -> System.IO.FileInfo
Public Function Replace (destinationFileName As String, destinationBackupFileName As String, ignoreMetadataErrors As Boolean) As FileInfo
Parametreler
- destinationFileName
- String
Geçerli dosyayla değiştirilmek üzere dosyanın adı.
- destinationBackupFileName
- String
parametresi tarafından destinationFileName açıklanan dosyanın yedeğinin oluşturulacağı dosyanın adı.
- ignoreMetadataErrors
- Boolean
true değiştirilen dosyadan değiştirme dosyasına birleştirme hatalarını (öznitelikler ve ACL'ler gibi) yoksaymak için; aksi takdirde false.
Döndürülenler
FileInfo parametresi tarafından destinationFileName açıklanan dosya hakkındaki bilgileri kapsülleyen bir nesne.
- Öznitelikler
Özel durumlar
parametresi tarafından destinationFileName açıklanan yol yasal bir biçimde değildi.
-veya-
parametresi tarafından destinationBackupFileName açıklanan yol yasal bir biçimde değildi.
destinationFileName parametresi null'dir.
Geçerli FileInfo nesne tarafından açıklanan dosya bulunamadı.
-veya-
parametresi tarafından destinationFileName açıklanan dosya bulunamadı.
Geçerli işletim sistemi Microsoft Windows NT veya üzeri değildir.
Örnekler
Aşağıdaki örnek, bir dosyayı başka bir dosyayla değiştirmek ve değiştirilen dosyanın yedeğini oluşturmak için yöntemini kullanır Replace .
using System;
using System.IO;
namespace FileSystemExample
{
class FileExample
{
public static void Main()
{
try
{
// originalFile and fileToReplace must contain the path to files that already exist in the
// file system. backUpOfFileToReplace is created during the execution of the Replace method.
string originalFile = "test.txt";
string fileToReplace = "test2.txt";
string backUpOfFileToReplace = "test2.txt.bak";
if (File.Exists(originalFile) && (File.Exists(fileToReplace)))
{
Console.WriteLine("Move the contents of " + originalFile + " into " + fileToReplace + ", delete "
+ originalFile + ", and create a backup of " + fileToReplace + ".");
// Replace the file.
ReplaceFile(originalFile, fileToReplace, backUpOfFileToReplace);
Console.WriteLine("Done");
}
else
{
Console.WriteLine("Either the file {0} or {1} doesn't " + "exist.", originalFile, fileToReplace);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadLine();
}
// Move a file into another file, delete the original, and create a backup of the replaced file.
public static void ReplaceFile(string fileToMoveAndDelete, string fileToReplace, string backupOfFileToReplace)
{
// Create a new FileInfo object.
FileInfo fInfo = new FileInfo(fileToMoveAndDelete);
// replace the file.
fInfo.Replace(fileToReplace, backupOfFileToReplace, false);
}
}
}
//Move the contents of test.txt into test2.txt, delete test.txt, and
//create a backup of test2.txt.
//Done
Imports System.IO
Module FileExample
Sub Main()
Try
' originalFile and fileToReplace must contain the path to files that already exist in the
' file system. backUpOfFileToReplace is created during the execution of the Replace method.
Dim originalFile As String = "test.xml"
Dim fileToReplace As String = "test2.xml"
Dim backUpOfFileToReplace As String = "test2.xml.bak"
If (File.Exists(originalFile) And (File.Exists(fileToReplace))) Then
Console.WriteLine("Move the contents of " + originalFile + " into " + fileToReplace + ", delete " + originalFile + ", and create a backup of " + fileToReplace + ".")
' Replace the file.
ReplaceFile(originalFile, fileToReplace, backUpOfFileToReplace)
Console.WriteLine("Done")
Else
Console.WriteLine("Either the file {0} or {1} doesn't " + "exist.", originalFile, fileToReplace)
End If
Catch e As Exception
Console.WriteLine(e.Message)
End Try
Console.ReadLine()
End Sub
' Move a file into another file, delete the original, and create a backup of the replaced file.
Sub ReplaceFile(ByVal fileToMoveAndDelete As String, ByVal fileToReplace As String, ByVal backupOfFileToReplace As String)
' Create a new FileInfo object.
Dim fInfo As New FileInfo(fileToMoveAndDelete)
' Replace the file.
fInfo.Replace(fileToReplace, backupOfFileToReplace, False)
End Sub
End Module
' Move the contents of test.txt into test2.txt, delete test.txt, and
' create a backup of test2.txt.
' Done
Açıklamalar
yöntemi, Replace belirtilen dosyanın içeriğini geçerli FileInfo nesne tarafından açıklanan dosyanın içeriğiyle değiştirir. Ayrıca değiştirilen dosyanın yedeğini de oluşturur. Son olarak, üzerine yazılan dosyayı açıklayan yeni FileInfo bir nesne döndürür.
Değiştirilen dosyanın yedeğini null oluşturmak istemiyorsanız parametresine geçindestinationBackupFileName.