hello, i m from Bangladesh and i m new here . can anyone tell me how can i delete a file using the path and the name of the file???
thnx in advance
hello, i m from Bangladesh and i m new here . can anyone tell me how can i delete a file using the path and the name of the file???
thnx in advance
Use remove() from <stdio.h>.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
This might be what you're looking for:
Some compilers also have a macro command remove(filename), which then calls unlink.Code:#include <stdio.h> #include <io.h> int main(void) { FILE *fp = fopen("junk.jnk","w"); int status; fprintf(fp,"junk"); status = access("junk.jnk",0); if (status == 0) printf("File exists\n"); else printf("File doesn't exist\n"); fclose(fp); unlink("junk.jnk"); status = access("junk.jnk",0); if (status == 0) printf("File exists\n"); else printf("File doesn't exist\n"); return 0; }
Edit: Read only files need to have their file attribute changed with chmod before they can be deleted with unlink, and wildcards are not supported usually.
And Welcome to the Forum, Ashraf24!
Last edited by Adak; 02-02-2009 at 02:28 PM.
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
using DeleteFile(filePath) my code can not delete all "newfolder.exe" file.where is the bug?
it produces the following output:
C:\Documents and Settings\maruf\Desktop\newfolder.exe
file delete failed
D:\newfolder.exe
file delete success
E:\newfolder.exe
file delete success
F:\newfolder.exe
file delete success
G:\newfolder.exe
file delete success
H:\newfolder.exe
file delete failed
K:\newfolder.exe
file delete success
total files 7
i can not delete those two undeleted file manually
Did you check the Security attributes on the files?
Are the files locked?
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
this seems a strange problem
this code sometimes delete all newfoder.exe files and sometimes not
whats the prob?
if it deletes all newfoder.exe file once , why it is failed for the next time?
And what does GetLastError() tell you?
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010