?
Solved

basic file functions

Posted on 1998-07-30
4
Medium Priority
?
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
4 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 200 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses

752 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