using namespace System::IO;

Does file exist?

	if (File::Exists("c:\\temp.txt"))

Copy File

	File::Copy("c:\\temp1.txt", "c:\\temp2.txt");

Move File

	File::Move("c:\\dir1\\temp1.txt", "c:\\dir2\\temp1.txt");	//Source, Destination

Delete File

		if (File::Exists("c:\\temp.txt"))
			//If file has read only attribute set clear it so that delete can occur
			if ((File::GetAttributes("c:\\temp1.txt") & FileAttributes::ReadOnly) == FileAttributes::ReadOnly)
				File::SetAttributes("c:\\temp1.txt", FileAttributes::Normal);

	catch (IOException ^)
		MessageBox::Show(L"This file is in use by another application - please close it first", L"Can't overwrite file", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);

Rename File

			"c:\\temp1.txt",			//Source
			"c:\\temp1.txt"	//Destination

Get File Size

	System::IO::FileInfo ^FileInfo1 = gcnew System::IO::FileInfo(FilenameWithPath);
	FileSize = FileInfo1->Length;

Get File Attributes

if ((File::GetAttributes(FilenameWithPath) & FileAttributes::ReadOnly) == FileAttributes::ReadOnly)
						ReadOnly = true;

Open / Close File Dialog Box

See Dialog Boxes…

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.


Your email address will not be published.