Click here to Skip to main content
15,891,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have developed an application to lock the folder.Below is the code that i use for locking the folder.Normally the code works fine if the folder/file name doesnt contain any spaces.(Example: Folder Name - Test Folder) and if the folder name is TestFolder then the code works fine and the folder is locked properly.Can i help where exactly its going wrong.

Thanks in Advance.

C++
char pass[15]="";
ofstream lfolder;
char folder[200]={0};
CString Foldername;
CString drive;
char tempfolder[200]={'0'};
char attributes[50]={'0'};

drive = "D:\\TestFolder";

sprintf_s(folder, "%s", drive);
strcpy(tempfolder, folder);

strcat(folder, "\\Desktop.ini");

lfolder.open(folder, ios::out);

lfolder << "[.shellClassInfo]" << endl;
lfolder << "CLSID = {2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}" << endl;

lfolder.close();

strcpy(attributes, "attrib +h +s ");
strcat(attributes, tempfolder);

WinExec(attributes, NULL);
Posted
Updated 14-May-13 18:47pm
v3

1 solution

You are building a string that attempts to set the characteristics with a command line operation via WinExec(). You need to build the command line so that the filename shows up in double quotes. For example the command line you are building for "C:\\Test Folder" is 'attrib +h +s C:\\Test Folder' and it should be 'attrib +h +s "C:\\Test Folder"'.
 
Share this answer
 
Comments
Rocky_Bas 15-May-13 0:24am    
Sorry Brydon i didnt get u.
H.Brydon 15-May-13 0:46am    
strcpy(attributes, "attrib +h +s \"");
strcat(attributes, tempfolder);
strcat(attributes, "\"");

Also you should really get in the habit of using strcpy_s() and strcat_s() for this type of code. There are several other coding indiscretions that I'll save for another time.
Rocky_Bas 15-May-13 1:06am    
Thanks Brydon that worked fine.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900