How to read file from local directory path
-
I have one function which reads file and does the conversion part. fp=fopen("newfile.txt","r"); Here i have copied this newfile.txt in project file and compiling in VC++ 2008 IDE.It works fine I would like to read the file from a local drive directory path.is it possible to read the files from local drive.how to mention the path.If so please mention any example. one more thing If i want to read all the files in that particular folder with out changing the name of text files in the above code. Suggest me any thing to do. I dont want to change the file name manully in the code
-
Answer:
You could use an absolute path to your file: FILE* fp = fopen("c:\\your_dir\\your_file.txt", "r"); if(fp) { // do something fclose(fp); } or a relative path, assuming your file is located in c:/etc and your executable is located in c:/etc/executables: FILE* fp = fopen("../your_file.txt", "r"); if(fp) { // do something fclose(fp); }
user1140755 at Stack Overflow Visit the source
Related Q & A:
- How to read csv file using php?Best solution by Stack Overflow
- How to Read xml file in java?Best solution by Stack Overflow
- How to read UTF-8 .txt file in Android?Best solution by wiki.mcneel.com
- How to write temporary files from temporary path to a temporary directory?Best solution by msdn.microsoft.com
- How to read file from specific word in php?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.