CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2001
    Posts
    745

    Locating a File To Read

    Hi All,

    In the command line of my program,Iam giving the path of an ini file.

    say:F:\Develop\InitialFile.ini

    In the same Path,I have ie: in F:\Develop.I have other files

    File1
    File2
    File3
    File4
    File5
    Now,I want to access these file form this location to read the contents of the files.I know how to read these files.How Can I locate these files to read?
    The code should not be windows dependent as I want to compile it under linux as well

    Could Anyone Help?

    Thanks in advance

  2. #2
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347
    In my opinion, you should abstract file-paths. You create a
    wrapper class that would internally handle all file-path formatting
    and you could use a common format in your program. As a simple
    example, you could construct a FilePath object with a path taking
    forward slashes; internally it'd convert all forward slashes to
    back-slashes on windows systems, but leave them alone on unix
    systems. After implementing this wrapping functionality, you could
    do a simple search by using std::string::find_last_of and look for
    the last directory delimiter [which is '\' on WIN32, but '/' in the
    unix world; with your wrapper class, you'd only have to worry
    about one of them].

    Instead of worrying about a wrapper class, you could also use
    constants like DIRECTORY_DELIMITER explicitly in your code and
    build file paths in that fashion; the disadvantage of that approach
    would be that accepting user-input would be harder ... and you
    wouldn't be able to have const char* filenames; you'd have to
    convert them all with some sort of routine. There are tradeoffs
    either way, I guess.

    --Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured