Computing.Net > Forums > Programming > c++ deleting a file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

c++ deleting a file

Reply to Message Icon

Name: texuser74
Date: November 23, 2004 at 21:55:04 Pacific
OS: Win & Linux
CPU/Ram: intel 512
Comment:

I have used system("del temp.txt") to delete a file before.

But now i want to delete a file whose filename is stored in the string variable "fname" and the extensions at "ext1", "ext2" & "ext3". So how to delete the 1 and 3 files with the same name but with 2 different extensions. I want to retain the file with the extension "ext2".




Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: November 24, 2004 at 07:35:56 Pacific
Reply:

Using system:

char filename[100];

sprintf(cmd,"del %s.ext1 %s.ext3",fname,fname);
system(cmd);


I'm assuming that "del file.ext1 file.ext3" is a valid way to delete two files. If not, you'd just build the "cmd" twice, once for each filename, and run system twice.


Also, you might look up "unlink" in your compiler docs. I believe that some compilers support this for deleting files.

Be sure to come back and let us know if our suggestions helped!


0
Reply to Message Icon

Related Posts

See More


Computer temp. in VB6 Command Button Behaviour-...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: c++ deleting a file

deleting a file (C++) www.computing.net/answers/programming/deleting-a-file-c/12045.html

deleting a file with CBuilderX www.computing.net/answers/programming/deleting-a-file-with-cbuilderx/12046.html

Deleting a file in VB www.computing.net/answers/programming/deleting-a-file-in-vb/18199.html