Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 12-02-2004, 04:40 PM   #1 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
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.
Androto is offline   Reply With Quote
Old 12-02-2004, 05:57 PM   #2 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
also, is it possible to get a window to open, then pic the files yourself?
Androto is offline   Reply With Quote
Old 12-08-2004, 07:49 PM   #3 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
Help!!!!
Androto is offline   Reply With Quote
Old 12-09-2004, 03:25 AM   #4 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
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++.
__________________
Valmont is offline   Reply With Quote
Old 12-09-2004, 06:14 AM   #5 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,711
redhead is on a distinguished road
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.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 12-11-2004, 04:50 PM   #6 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
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.
Androto is offline   Reply With Quote
Old 12-11-2004, 09:32 PM   #7 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
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.
__________________
Valmont is offline   Reply With Quote
Old 12-13-2004, 05:52 PM   #8 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
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.
Androto is offline   Reply With Quote
Old 12-13-2004, 05:55 PM   #9 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
I've edited your code. Now it works.
__________________
Valmont is offline   Reply With Quote
Old 12-13-2004, 05:57 PM   #10 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
did you really, because i was editing it at the same time.

LOL
Androto is offline   Reply With Quote
Old 12-13-2004, 07:00 PM   #11 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
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.
__________________
Valmont is offline   Reply With Quote
Old 12-14-2004, 10:00 AM   #12 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
it doesn't work.
Androto is offline   Reply With Quote
Old 12-14-2004, 12:02 PM   #13 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
What doesn't work exactly?
__________________
Valmont is offline   Reply With Quote
Old 12-14-2004, 06:37 PM   #14 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
it says the errors at the top
Androto is offline   Reply With Quote
Old 12-15-2004, 03:06 AM   #15 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
I don't see anything.
__________________
Valmont is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
reading files from a directory and printing philthee Java 4 10-29-2004 05:01 AM
Installing and using CMUgraphics library. Valmont Standard C, C++ 12 03-29-2003 08:39 AM
Linking files? ShadowSoft Standard C, C++ 3 02-27-2003 12:33 PM
All Class Files mixingsoup PHP 12 12-04-2002 06:49 AM


All times are GMT -8. The time now is 08:52 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting