TOP C++/CLR


FILE

backup file

// rename
    if (File::Exists(fname+".bak")){
        File::Delete(fname+".bak");
    }
    if (File::Exists(fname)){
        File::Move(fname,fname+".bak");
    }
    File::Move(tempFileName,fname);

append to log

How to: Open and Append to a Log File
File.AppendText Method (String) : If the file specified by path does not exist, it is created. If the file does exist, write operations to the StreamWriter append text to the file. Additional threads are permitted to read the file while it is open.
    String^ log_txt=System::Environment::GetFolderPath( Environment::SpecialFolder::MyDocuments )+"\\"+"hoge.log";
    System::IO::StreamWriter^ w = System::IO::File::AppendText(log_txt);
    w->WriteLine("{0} [{1}] {2}",DateTime::Now, label0->Text,label1->Text);
    w->Close();

String

Path

System::IO::Path Class
ChangeExtension(String^, String^)Changes the extension of a path string.
Combine(String^, String^)Combines two strings into a path.
Combine(String^, String^, String^)Combines three strings into a path.
Combine(String^, String^, String^, String^)Combines four strings into a path.
Combine(array<String^>^)Combines an array of strings into a path.
GetDirectoryName(String^)Returns the directory information for the specified path string.
GetExtension(String^)Returns the extension of the specified path string.
GetFileName(String^)Returns the file name and extension of the specified path string.
GetFileNameWithoutExtension(String^)Returns the file name of the specified path string without the extension.
GetFullPath(String^)Returns the absolute path for the specified path string.
GetInvalidFileNameChars()Gets an array containing the characters that are not allowed in file names.
GetInvalidPathChars()Gets an array containing the characters that are not allowed in path names.
GetPathRoot(String^)Gets the root directory information of the specified path.
GetRandomFileName()Returns a random folder name or file name.
GetTempFileName()Creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file.
GetTempPath()Returns the path of the current user's temporary folder.
HasExtension(String^)Determines whether a path includes a file name extension.
IsPathRooted(String^)Gets a value indicating whether the specified path string contains a root.

Environment

Environment::GetFolderPath Method (Environment::SpecialFolder)Environment::SpecialFolder Enumeration
MyDocuments,MyMusic
Environment::GetFolderPath( Environment::SpecialFolder::System );
Environment::ExpandEnvironmentVariables Method (String^)A string with each environment variable replaced by its value.String^ query = "My system drive is %SystemDrive% and my system root is %SystemRoot%";
String^ str = Environment::ExpandEnvironmentVariables( query );

管理人/副管理人のみ編集できます