Error when changing file name

closed account (iGLbpfjN)
I'm doing a folder locker that works like the .bat notepad file.
If I put the password inside the .cpp file, it works perfectly. But I wanna put the password when running the program.
To do that, I tried to create a .dat file that save the password as a string. Then, it'll be hidden and appear when is needed to check the password the user entered.
The problem is that, after creating the file and adding the password, it show me that the final file wasn't found.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
checkDir("Private.{21EC2020-3AEA-1069-A2DD-08002B30309D}");
// This will check if the file in parenthesis exists
checkDir("Private");
// This will check if the file in parenthesis exists

string password;
fstream passwordSave;

if (checkDir("Private") == false && checkDir("Private.{21EC2020-3AEA-1069-A2DD-08002B30309D}") == false)
// false = doesn't exists  
{
     system("md Private");
// This will create the directory to add the itens to be hidden

     cout << "Insert the password: ";
     cin >> password;

     passwordSave.open("Password.dat");  // The file to save the pass

     passwordSave << password;

     MoveFile("Password.dat", "Password.{21EC2020-3AEA-1069-A2DD-08002B30309D}.dat")
// I REALLY DON'T KNOW IF THE SYNTAX IS CORRECT --> Maybe this is the problem?

     system("attrib +h Password.{21EC2020-3AEA-1069-A2DD-08002B30309D}.dat");
// This file isn't found
     
     return 0;
}
Last edited on
Since a stream is buffered you should close (or at least flush) the file before you move it.

Side not: consider using the API functions instead of system().

SetFileAttributes:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365535(v=vs.85).aspx

CreateDirectory:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx
closed account (iGLbpfjN)
Oh! Thank you! It worked! ^^
Topic archived. No new replies allowed.