|
 |
|
 |
12-02-2004, 04:40 PM
|
#1 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
reading a folder of files
i'm trying to create a program which can read a perticualr type of file from a folder. i'm look for the all the files which do not end have an extension. the number of characters of each file name is 36 characters before the extention.
i.e. ABCDEFGHIJ LKMNO PQRST UVWXY ZABCD EFGHI.state
the file name is 36 characters up to but not including the decimal.
so basicly, all i want to know how to do is read in files which do not have an extension. the rest of the code, i think i could do by myself.
|
|
|
12-02-2004, 05:57 PM
|
#2 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
also, is it possible to get a window to open, then pic the files yourself?
|
|
|
12-08-2004, 07:49 PM
|
#3 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
Help!!!!
|
|
|
12-09-2004, 03:25 AM
|
#4 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
|
Creating and reading files is simple enough. The code below assumes the file is in the project folder.
You will need to add this if the file is in another folder:
"c:/windows/temp/whatever/...."
Code:
int main(int argc, char *argv[])
{
ofstream createOpenTest("ABCDEFGHIJ LKMNO PQRST UVWXY ZABCD EFGHI.state");
int a(0);
createOpenTest<<5;
createOpenTest.close();
ifstream readOpenTest("ABCDEFGHIJ LKMNO PQRST UVWXY ZABCD EFGHI.state");
readOpenTest>>a;
readOpenTest.close();
cout<<a<<endl;
return 0;
}
But opening windows and loading pictures is a win32 issue. I don't cover api's. Besides, that is offtopic in this forum, since here we only deal with standard C and C++.
__________________
|
|
|
12-09-2004, 06:14 AM
|
#5 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,711
|
sounds to me, what he is looking for is a way of reading which files that are in a directory, only showing the user the ones with a specific type (ie. .doc, .exl, .txt, etc.) then the user can chose which of these files to open and read in.
something like [pseudocode]
Code:
struct dirent * curr_dir;
DIR* my_dir;
my_dir = opendir("some_dir");
while (curr_dir = readdir(my_dir))
{
if(!my_ending(curr_dir.d_name))
/* don't show user */
else
/* show user filename */
}
I know this is very system depending on the structures and opendir()/readdir() calls, thats why I've kept away from this untill now..
And as valmont points out, it is not strict C/C++ thus more apropriate in the Platform/API C++ section. besides the thing with a "user chose from list" sounds to me like a very GUI based solution, which is way beond what you'd expect in a strict C/C++ programming.
|
|
|
12-11-2004, 04:50 PM
|
#6 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
Quote:
|
Originally Posted by Valmont
Creating and reading files is simple enough. The code below assumes the file is in the project folder.
You will need to add this if the file is in another folder:
"c:/windows/temp/whatever/...."
Code:
int main(int argc, char *argv[])
{
ofstream createOpenTest("ABCDEFGHIJ LKMNO PQRST UVWXY ZABCD EFGHI.state");
int a(0);
createOpenTest<<5;
createOpenTest.close();
ifstream readOpenTest("ABCDEFGHIJ LKMNO PQRST UVWXY ZABCD EFGHI.state");
readOpenTest>>a;
readOpenTest.close();
cout<<a<<endl;
return 0;
}
But opening windows and loading pictures is a win32 issue. I don't cover api's. Besides, that is offtopic in this forum, since here we only deal with standard C and C++.
|
if i'm using os x will that change anything?
also, how do i get this code to work? what libraries do i have to include?
Last edited by Androto; 12-11-2004 at 05:52 PM.
|
|
|
12-11-2004, 09:32 PM
|
#7 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
|
It will work on osx as well:
Include fstream and iostream. All in namespace std. You can see all over this forum on how to do that.
__________________
|
|
|
12-13-2004, 05:52 PM
|
#8 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
so would this be the entire code for it to work?
Code:
#include <fstream>
#include <iostream>
int main(int argc, char *argv[])
{
ofstream createOpenTest("ABCDEFGHIJ LKMNO PQRST UVWXY ZABCD EFGHI.state");
int a(0);
createOpenTest<<5;
createOpenTest.close();
ifstream readOpenTest("ABCDEFGHIJ LKMNO PQRST UVWXY ZABCD EFGHI.state");
readOpenTest>>a;
readOpenTest.close();
cout<<a<<endl;
return 0;
}
i don't understand the following parts:
what is "createOpentest"? and also, why is there the name of the file in the brackets? i was trying to get all the files which end in .state?
Code:
ofstream createOpenTest("ABCDEFGHIJ LKMNO PQRST UVWXY ZABCD EFGHI.state");
i've got the same questions for the following code.
Code:
ifstream readOpenTest("ABCDEFGHIJ LKMNO PQRST UVWXY ZABCD EFGHI.state");
basically, could you just explain your code briefly.
thx in adv.
|
|
|
12-13-2004, 05:55 PM
|
#9 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
|
I've edited your code. Now it works.
__________________
|
|
|
12-13-2004, 05:57 PM
|
#10 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
did you really, because i was editing it at the same time.
LOL
|
|
|
12-13-2004, 07:00 PM
|
#11 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
|
Code:
Code:
#include <fstream>
#include <iostream>
int main(int argc, char *argv[])
{
ofstream createOpenTest("ABCDEFGHIJ LKMNO PQRST UVWXY ZABCD EFGHI.state");
int a(0);
createOpenTest<<5;
createOpenTest.close();
ifstream readOpenTest("ABCDEFGHIJ LKMNO PQRST UVWXY ZABCD EFGHI.state");
readOpenTest>>a;
readOpenTest.close();
cout<<a<<endl;
return 0;
}
If you want to know what it does then read a basic tutorial on file streams.
__________________
|
|
|
12-14-2004, 10:00 AM
|
#12 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
it doesn't work.

|
|
|
12-14-2004, 12:02 PM
|
#13 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
|
What doesn't work exactly?
__________________
|
|
|
12-14-2004, 06:37 PM
|
#14 (permalink)
|
|
Mac Os X User(I hate win)
Join Date: Oct 2004
Posts: 138
|
it says the errors at the top
|
|
|
12-15-2004, 03:06 AM
|
#15 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
|
I don't see anything.
__________________
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 08:52 AM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|