Click to See Complete Forum and Search --> : Reading filenames from directories...
Randy H
May 17th, 1999, 01:45 AM
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
suganyas
May 17th, 1999, 02:08 AM
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
Randy H
May 17th, 1999, 02:16 AM
Worked great thanks.
BrianOG
May 17th, 1999, 05:01 AM
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.
sally
May 17th, 1999, 07:38 AM
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
Sally
May 17th, 1999, 07:38 AM
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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.