header
CodePanic! > C#.NET Tips > 今ここ

■ファイルの移動/ファイル名の変更

System.IO.File.Move()関数を使います。
移動元ファイル名と
移動先ファイル名を指定します。

// ファイルを移動する(移動の際、ファイル名を変更しても構いません)
//
// ※移動元ファイルが無い場合
//      例外:System.IO.FileNotFoundException   が発生します。
// ※移動先ファイルが既に存在する場合
//      例外:System.IO.IOException             が発生します。
System.IO.File.Move( @"C:\hello.txt", @"C:\Temp\hello.txt" );

// 移動元と移動先のフォルダが同じであれば名前を変更したことになります。
System.IO.File.Move( @"C:\hello.txt", @"C:\unko.txt" );





Copyright © 2008.07 - shougo suzaki