CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 1999
    Posts
    4

    Reading filenames from directories...

    I would like to write some code that can compile lists of files in directories. Using the CFileFind class, I've been successful at getting the filenames. The problem is (and this may sound silly) that I don't know how to set the working directory for the CFileFind operation. The only way I have been able to do this is by setting the ENTIRE project's working directory. What is the command used to change the working directory during program execution?

    Thanks,
    Randy


  2. #2
    Join Date
    May 1999
    Posts
    29

    Re: Reading filenames from directories...

    Hi!
    U can use _chdir to change the current working directory.The _chdir function changes the current working directory to the directory specified by dirname. The dirname parameter must refer to an existing directory. This function can change the current working directory on any drive and if a new drive letter is specified in dirname, the default drive letter will be changed as well. For example, if A is the default drive letter and \BIN is the current working directory, the following call changes the current working directory for drive C and establishes C as the new default drive:

    _chdir("c:\\temp");

    U need to #include the direct.h header file.
    #include <direct.h>

    Do let me know if it works.
    Regards,
    Sukanya Swaminathan
    Software Engineer
    Aditi Technologies
    Blore - 80
    Web Page :www.aditi.com


  3. #3
    Join Date
    May 1999
    Posts
    4

    Re: Reading filenames from directories... (IT WORKED)

    Worked great thanks.


  4. #4
    Join Date
    May 1999
    Posts
    116

    Re: Reading filenames from directories... (IT WORKED)

    Be sure to save the current dir, and set it back when finished, as its not nice to change the working dir on the user.

    Another way is to specify the directory in the filter for CFileFind::FindFile.
    E.g.:CFileFind fileFind;
    fileFind.FindFile("c:\\tmp\\*.*")

    This works with FindFirstFile/FindNextFile, so I presume it should work here also.


  5. #5
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: Reading filenames from directories... (IT WORKED)

    It does, I always use this method as I hesitate on changing the current workingdirectory for a user

    multi threaded applications can get really upset if you do...

    Sally


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