How can I delete a file? I'm making a windows program so I can't use any dos functions.
Printable View
How can I delete a file? I'm making a windows program so I can't use any dos functions.
Yes you can.Quote:
How can I delete a file? I'm making a windows program so I can't use any dos functions.
remove( filename );
Ok, that works except the file I'm try to delete has spaces in it, and there are forward slashes in it for the folder it is in. Anyone know how I can delete this file without changing the filename?
That shouldn't matter. What is the filename?
You shouldn't have to change the filename. I've deleted files with spaces in the name before with no trouble. For the slashes for the path just use double-slashes.Quote:
Originally posted by pinkcheese
Ok, that works except the file I'm try to delete has spaces in it, and there are forward slashes in it for the folder it is in. Anyone know how I can delete this file without changing the filename?
ie:
The file you want to delete is:
backup\back up.txt
use:
Code:remove("backup\\back up.txt");
The file I am trying to delete it: "C:\Downloaded Music\Bjork - Unravel.mp3".
I've tried remove("C:\Downloaded Music\Bjork - Unravel.mp3") and it doesn't work.
If I rename the file to "Bjork-Unravel.mp3" and then put the program in the Downloaded Music folder and use remove("Bjork-Unravel.mp3") it does work.
I wonder why? Change that to remove("C:/Downloaded Music/Bjork - Unravel.mp3")Quote:
I've tried remove("C:\Downloaded Music\Bjork - Unravel.mp3") and it doesn't work.
Maybe I'm wrong but I though it was:Quote:
I've tried remove("C:\Downloaded Music\Bjork - Unravel.mp3") and it doesn't work.
remove("C://Downloaded Music//Bjork - Unravel.mp3");
Or something similar.
Sorry guys, remove("c:/Will's/Etcetera MP3 source/Downloaded Music/Bjork - Unravel.mp3") does work. It appers that my problem is somewhere else.
Does this method work only for Windows or will it work for Linux too?
Well, as far as I know stdio.h is a standard header... so I would think it would work with Linux. Go search the man pages for it, I'm sure you'll come across it or something similar.
Yeah. Your problem was that when you include a single backslash in a string, it treats it as an escape code. Thus:Quote:
It appers that my problem is somewhere else.
"c:\program files"
Actually means:
"c:[ESCAPE-P]rogram files"
Quzah.
you should goTo put a '\' char into a string literal, you must go "\\".Code:remove("C:\\Downloaded Music\\Bjork - Unravel.mp3");