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…

We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published.