I just started taking a c++ course and as a hobby programmer i have created an assignment for myself. The assignment is very simple. I have a folder with some content in it in windows OS and i want to delete all the folder content with sub-folders as well. for a start i used a path 'c:\Users\username\MyVideo\'
1) To find the username in the path i tried using GetUserName() function and try to use strcat(str1,str2) to concate the entire path; but it gave an error because It says GetUserName gives CHAR array and can't convert it to std::string. I have attached the sample code for that. I saw a solution for that like----
" #ifndef UNICODE
typedef std::string String; #else typedef std::wstring String; #endif "
but i don't know what it is. where to put it in my code and what does it do.
My Code:--- #define INFO_buffer_size 32767
int main() {
string str1,str3,str4;
TCHAR str2[INFO_buffer_size];
DWORD charCount = INFO_buffer_size;
str1 = "C:\\Users\\ " ;
GetUserName((TCHAR*)str2,&charCount);
// strcat(str1,str2); **gives error here**
//str3 = "\\MyVideo" ;
//str4 = str1+str2+str3;
return 0;
}
2) I want to find a specific Folder Path ? ( for e.g. instead of specifying 'c:\Users\username\MyVideo\' i want to only type in find a path for MyVideo folder and it should look it up itself to make it more generic)Is there a function or an efficient way to do that?
3) I want to remove the content of MyVideo folder and its subfolders. Is there a function or an efficient way to delete the content?
In your solutions if you guys can explain a bit why you wrote the solution u chose will help me understand alot. Thanks for your help. :)
Aucun commentaire:
Enregistrer un commentaire