Jonathan Mcdougall wrote in news:Y0Efb.58362$1M6.1109254
@wagner.videotron.net:
[color=blue][color=green]
>> I am a c programmer and new to C++. In C, I am familiar with some
>> operations on file. Now when shifting from c to c++, using iostream, I
>> have no idea how to perform the following operations
>>
>> 1. check if a file or directory exists or not[/color]
>
> std::ifstream check("file.ext");
>
> if ( ! check )
> std::cout << "file does not exist";[/color]
All this realy tells you is there was an error when you tried
to open the file for reading, It may be enough to know this but
it isn't a portable "file does not exist".
You could, having failed to open it, then try to create and write
to it, if this succeeds then the file *probably* didn't exist.
[color=blue]
>[color=green]
>> 2. delete all the files under a given directory[/color]
>
> No, unless you have the file list. Remove a single file with
>
> std::remove("filename");
>
> from <cstdio> iirc. You'll have to use some implementation-specific
> functions to get more informations about the file system.
>[color=green]
>> 3. rename[/color]
>
> No, except by copying under a new name and then remove the old
> one.
>
>[/color]
int std::rename(const char *old, const char *new);
http://www.dinkumware.com/manuals/re...io.html#rename
Rob.
--
http://www.victim-prime.dsl.pipex.com/