Computing.Net > Forums > Programming > C++ help for beginner

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C++ help for beginner

Reply to Message Icon

Name: kevin_af
Date: February 28, 2004 at 19:22:42 Pacific
OS: WinXP
CPU/Ram: P4
Comment:

disclaimer: C++ newbie here...


I want to be able to have my code delete a file from the current directory. For example:


char x[9]="file.exe";
system("del" x);

The reason I dont just put system("del file.exe") is because I want to be able to come back and change the file name later without having to search my code for every instance of it.

Anyone know how I can do this?

Thanks!




Sponsored Link
Ads by Google

Response Number 1
Name: Fozzie
Date: February 28, 2004 at 19:40:42 Pacific
Reply:

I know how I would do it using the Windows API, but not to sure about standard C++.

but..

I believe you can use:

char delFile[50]="";
char x[9]="file.exe";

sprinft(delFile, "del %s", x);

system(delFile);


If you need to delete files with REALLY long paths you would need to make the character array delFile larger.


0

Response Number 2
Name: Ronin1
Date: February 28, 2004 at 20:22:51 Pacific
Reply:

There is an ANSI function specifically for deleting files: int remove(const char* filename) from stdio.h

You may also look into unlink. Either returns 0 on successful deletion of the file.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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++ help for beginner

C++ - need FOR loop help www.computing.net/answers/programming/c-need-for-loop-help/9209.html

Reccomended C# Book for Beginner. www.computing.net/answers/programming/reccomended-c-book-for-beginner/14496.html

good c++ book for recommendation www.computing.net/answers/programming/good-c-book-for-recommendation-/13051.html