Delete file based on number [i]
Mar 15, 2014 at 8:01am UTC
Hi I have written a program that allow user to add in their file. But now I want to allow the user to to delete the file too. But I was not sure how could I start by deleting the file. So the following codes are the skeleton structure where user enter the number [i] based on the available list. Appreciate your help! Thanks!
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
case 'D' :
case 'd' :
myfiles = getFiles();
cout << "Current available objects:" << endl;
for (int i = 0; i < myfiles.size(); i++)
cout << '[' << i << ']' << ' ' << myfiles[i] << endl;
cout << endl << "Enter file number to delete or \"end\" to exit:" ;
while (cin >> str)
{
if (str == "end" )
break ;
input = str2int(str);
if (input >= 0 && input < myfiles.size())
{
//Delete object
newname = ExePath() + "/data/" + myfiles[input];
name = new char [newname.size() - 1];
strcpy(name, newname.c_str());
remove(name);
//Print out the available objects
cout << "\nCurrent available objects:" << endl;
for (int i = 0; i < myfiles.size(); i++)
cout << '[' << i << ']' << ' ' << myfiles[i-1] << endl;
cout << endl << "Enter file number to delete or \"end\" to exit:" ;
}
else cout << "Invalid input." << endl;
}
break ;
Last edited on Mar 15, 2014 at 8:13am UTC
Topic archived. No new replies allowed.