To get rid of a directory, you can call the RemoveDirectory() function of the Win32 library. Its syntax is: BOOL WINAPI RemoveDirectory(__in LPCTSTR lpPathName); When calling this function, pass the complete path as argument. If the path exists, the function would delete it. Here is an example: void CExerciseDlg::OnBnClickedDeleteDirectoryBtn()
{
if( RemoveDirectory(L"C:\\Exercise1\\Exercise2") == TRUE )
AfxMessageBox(L"The directory has been deleted");
}
An alternative is to call the DeleteFile() function of the Win32 library.
To rename a directory, you can call the MoveFile() function of the win32 library. Its syntax is: BOOL WINAPI MoveFile(__in LPCTSTR lpExistingFileName, __in LPCTSTR lpNewFileName); The first argument is the name and path of the directory you want to rename. To rename a directory, provide the same first part for the second argument. Change only the last that involves the actual directory to rename. Here is an example: void CExerciseDlg::OnBnClickedRenameDirectoryBtn() { if( MoveFile(L"C:\\Exercise\\Exercise1", L"C:\\Exercise\\Exercise2") == TRUE ) AfxMessageBox(L"The directory has been renamed"); }
If you want to move a directory, you can also call the same MoveFile() function. Pass the second argument as the complete and path for the new location:
void CExerciseDlg::OnBnClickedMoveDirectoryBtn() { if( MoveFile(L"C:\\Exercise1\\Exercise2", L"C:\\Exercise2\\Exercise2") == TRUE ) AfxMessageBox(L"The directory has been moved"); }
|
|
|||||||||
|