Hi everyone. I am trying to write a program that controls access to my hard drive.i.e when this program is running, the specified directory can not be accessed. But first, s there any way one can create a folder using c++?

I assume that you are asking this question for a windows system which won't let you create a directory from fstream so you need

#include <windows>
int main()
{
std::string folder("C:\\my_folder");
CreateDirectory(folder.c_str(), NULL);
return 0;
}

The Null is for the security settings which might let you lock the folder but I'm not sure whether you will be able to take control of the harddrive using legitimate means

Hi everyone. I am trying to write a program that controls access to my hard drive.i.e when this program is running, the specified directory can not be accessed. But first, s there any way one can create a folder using c++?

Thanks, tetron.. What I want to achieve is this: If the program is running, once the user tries to access a folder specified as inaccessible by the program,a messagebox would pop up, stopping the user from doing so.

If you mean access to a folder from outside of your program this is not easy to achieve as it is your operating system that controls the folder, although you can probably stop a user writing to the folder detecting it from outside the OS as your program would be is tricky.

It is doable in windows but it is black hat behaviour to alter the pop-ups from explorer etc. If you are inside your code it is much more managable to control the user.

Try reading up on locking folders and if that doesn't achieve what you need you could try opening a new thread explaining why you need this behaviour and there might be a different solution.

Thanks, tetron.. What I want to achieve is this: If the program is running, once the user tries to access a folder specified as inaccessible by the program,a messagebox would pop up, stopping the user from doing so.

This question has already been answered. Start a new discussion instead.