Open File Dialog

using namespace System::IO; Open File Dialog Example String ^LastFileDirectory; String ^Filename; //If last directory is not valid then default to My Documents (if you don’t include this the catch below won’t occur for null strings so the start directory is undefined) if (!Directory::Exists(LastFileDirectory)) LastFileDirectory = Environment::GetFolderPath(Environment::SpecialFolder::MyDocuments); //—– FILE OPEN DIALOG BOX —– OpenFileDialog ^SelectFileDialog = […]

Read More

Working With Files

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 try { 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); File::Delete(“c:\\temp1.txt”); } } catch (IOException ^) { MessageBox::Show(L”This […]

Read More

User select directory example

String ^SelectedDirectory; FolderBrowserDialog ^SelectFolderDialog = gcnew FolderBrowserDialog(); //Setup dialog box SelectFolderDialog->Description = “Select directory to store files to”; SelectFolderDialog->ShowNewFolderButton = true; SelectFolderDialog->RootFolder = System::Environment::SpecialFolder::Desktop; try { SelectFolderDialog->SelectedPath = SelectedDirectory; //Try and use last selection } catch (Exception ^) { } //Display dialog box if (SelectFolderDialog->ShowDialog() == System::Windows::Forms::DialogResult::OK) { SelectedDirectory = SelectFolderDialog->SelectedPath; //…………. }

Read More

Working With Directories

using namespace System::IO; Does directory exist? (Note paths can include a filename if you wish) if (!Directory::Exists(Path::GetDirectoryName(MyFileName))) //or String ^path; path = "C:\\Atest\\"; // '\\'='\' if (!Directory::Exists(path)) //or if (!Directory::Exists("C:\\Atest\\")) // '\\'='\' Create Directory (Note paths can include a filename if you wish) Directory::CreateDirectory(Path::GetDirectoryName(MyFileName)); //or String ^path; path = "C:\\Atest\\"; // '\\'='\' Directory::CreateDirectory(path); //or Directory::CreateDirectory("C:\\Atest\\"); […]

Read More