Solved

basic file functions

Posted on 1998-07-30
4
181 Views
Last Modified: 2010-04-02
Hi,
How can I:
1. delete file from a directory (I am not in this directory)?
2. edit a file , also, i am not in this file directory?
3. search a string in a file?
4. errors in finding file.

Thanks A lot,
Tomer Leicht
0
Comment
Question by:tomerl
  • 4
4 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
ID: 1169034
answers coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1169035
I assume we are talking standard C++ right?  you don't want to be using a specific OS's procedures, like the Windows API?

1. to delete a file use remove() from stdio.h or io.h.  You specify a string that is the path and file name of the file to be removed.

2.  editing a file can mean anything.  (editing a text file is very different than editing a database file)  I assume you mean you want to modify a file in some way.  I'll explain how to modify it in general, you will have to decide ont he specifics for you case.

  you open the file with fopen(), read data from it with fread(), write new data to it with fwrite(), seek to different positions for reading/writting with fseek() and close the file with fclose().  read about these and ask if you have questions.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1169036
3. you open the file and read it in memory then search for the string using strstr().  If the file is too large to read into memory at one time, you can read it in pieces and search each piece.  The danger is if the string starts at the end of one piece and ends at the start of another you won't find it.  There are ways around this.  The easiast (not the most efficeint) is to copy the last (n-1) bytes from the end of the buffer (piece) to the the start where n is the length of the string you are looking for.  Then read in the new piece after those n-1 bytes.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1169037
>> 4. errors in finding file.
what do you mean by this?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now