Hello,
I am currently Trying to rename a file to a randomly created string. Every time a file is passed to my program i want it to be renamed to a very random name always ending in '.dl'. However i am experience some difficulty's. When i pass a file to the program the file disappears totally.
Thank You For Any Help.
Here is the program:
The output is:Code:#include <iostream> #include <windows.h> #include <cstdio> char Random_Char; char Altered_Filename[16]; using namespace std; void Get_Random_Char() { Random_Char = (rand()%62); if(Random_Char <= 25) { Random_Char += 97; } else if(Random_Char >= 26 && Random_Char <= 51) { Random_Char += 39; } else if(Random_Char >= 52) { Random_Char -= 4; } } void Rename_The_File() { int Chars_In_Name = 0; srand(time(0)); do{ Get_Random_Char(); Altered_Filename[Chars_In_Name] = Random_Char; Chars_In_Name++; }while (Chars_In_Name != 13); Altered_Filename[13] = '.'; Altered_Filename[14] = 'd'; Altered_Filename[15] = 'l'; Altered_Filename[16] = '\0'; } int main(int argc, char *argv[]) { Rename_The_File(); cout << argv[1] <<"\n\n"; cout << Altered_Filename <<"\n\n"; system("pause"); if (rename(argv[1], Altered_Filename) != 0) { cout << "ERROR!!!\n\n"; } else { cout << "Sucess!!!\n\n"; } system("pause"); }
Code:C:\Documents and Settings\Chris\Desktop\New Text Document.txt hYtMPRRtUNAHA.dl Press any key to continue . . . Sucess!!! Press any key to continue . . .
(New Text Document.txt Is no longer on desktop nor is there a file called hYtMPRRtUNAHA.dl)



LinkBack URL
About LinkBacks




