| | |
Help with Searching files in Directories
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
I am trying to search for files in Directories.
like, i have 10 directories..... and consider directory 1, which has 2 files..
this is same with all the files...
i want to get a string from each of these files from 10 directories... to be written to a seperate file, in C++.
I have been trying to do this.... any help will be greatly appreciated.
Thank you
like, i have 10 directories..... and consider directory 1, which has 2 files..
this is same with all the files...
i want to get a string from each of these files from 10 directories... to be written to a seperate file, in C++.
I have been trying to do this.... any help will be greatly appreciated.
Thank you
Can you get a string from one file? If so then can you get a string from more than one file in the same directory? Do you have to search for the files according to some pattern, or do you have a list of filenames? I see this question a lot, and nobody gives enough detail. I need to know what you already know how to do. If you don't know how to open and read a file then my answering the question assuming your problem is with reading from multiple directories wouldn't help much. If you don't know how to open and read from different directories then I need to know what operating system and compiler you use because there's no portable solution for that problem.
Yes, i can get the string i want from one file, and from multiple files in one directory.
i have to search for the files, based on one String, and then get the data from those files.
i worked with files before, but no with searching for files in directories and arranging them in an array.
coz, there is parent directory, which has subfolders.these subfolders has files.
the OS is Winxp, VC++ compiler.
i have to search for the files, based on one String, and then get the data from those files.
i worked with files before, but no with searching for files in directories and arranging them in an array.
coz, there is parent directory, which has subfolders.these subfolders has files.
the OS is Winxp, VC++ compiler.
In that case the Win32 API would probably be your easiest solution. You can start browsing from here.
how about this function... any further help plzz
C++ Syntax (Toggle Plain Text)
private void GetFileInDirectory() { textfile = new string[200]; try { string [] files; string path = currentPictureFile.Substring(0, currentPictureFile.LastIndexOf("\\") + 1); if ( Directory.Exists(path) ) { files = Directory.GetFiles(path); int i = 0; foreach ( string fileName in files ) { int lastIndex = fileName.LastIndexOf("."); if ( fileName.Length - lastIndex - 1 == 3 ) { string ext = fileName.Substring(lastIndex + 1, 3).ToUpper(); if ( (ext.Equals("txt" ) ) { textfile[i++] = fileName; } } } } } catch (IOException ioE) { MessageBox.Show("Error - wrong path"); } catch (UnauthorizedAccessException unE) { } }
In another forum I posted a link to an FAQ: "Accessing a directory and all the files within it". Did you follow the link?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Other Threads in the C++ Forum
- Previous Thread: Skeleton for a game.
- Next Thread: Can't set memory!!
| Thread Tools | Search this Thread |
Tag cloud for C++
api array arrays based beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion count data delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference rpg simple string strings studio system temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets







But I still recommend using the Win32 API, and my link is a great start.