How to remove files

Hi,
again, I am a newbie to the programming and I need your help!
Well, I am just trying to learn the language for my hobby and free time.
But I need to get help to this....

I tried the Remove command like:
for Delete32.cpp:
_________________________________
// remove example: remove myfile.txt//

#include <stdafx.h>

int main ()
{
if( remove( "myfile.txt" ) == -1 )
perror( "error deleting file" );
else
puts( "File successfully deleted" );

return 0;
}
_______________________________________

and this, I used remove command (or I think)
to delete myfile.txt within the SAME directory
to where Delete32.cpp is located but,
how do i make it so that the remove command
will delete something OUTSIDE of the directory
which Delete32.exe resides

So now, I am trying to delete
"test" in the "C:\" Driver or "C:\test"
and that will delete anything inside of that...
Thank you for any help!


Keehun



Answer this question

How to remove files

  • Smithy196

    thank you VERY much for your help!

  • Chris Han MSFT

    thank YOU



  • Delphyne

    Hi,

    I don't think I fully understand your question. But I'll just give it a shot.

    Try using a statement like this remove("..\myfile.txt") I think this will remove files outside of your own directory. Or you could just specify the whole path to be more accurate...

     

    BTW, im moving your post in the C++ area. To avoid confusions...

     

    cheers,

    Paul June A. Domag



  • mon

    Thanks, and I understand your answer
    but can you be more specific

    Because I don't fully understand it...
    well, I'll give my shot too.
    To you mean something like this

    #include <stdafx.h>

    int main ()
    {
    if( remove( "../myfile.txt" ) == -1 )
    perror( "error deleting file" );
    else
    puts( "File successfully deleted" );

    return 0;
    }

    or is it possible to:

    #include <stdafx.h>

    int main ()
    {
    if( remove( "c:\test\" ) == -1 )
    perror( "error deleting file" );
    else
    puts( "File successfully deleted" );

    return 0;
    }


    well, THANKS!!!



  • themuuj

     KN1123 wrote:

    So now, I am trying to delete
    "test" in the "C:\" Driver or "C:\test"
    and that will delete anything inside of that...
    There is no reason remove() should not work, unless the file is locked for sharing or some other more arcane reason.  I suspect that you're only using a single backslash in your path names, like "C:\test".  Remember that the C++ compiler is performing special translation uses those backslashes, to turn "\n" into a new line, "\r" into a carriage return, "\t" into a tab, etc...  With C/C++, you need to use a double backslash; "C:\\test" is a correct path string.

  • How to remove files