struct dirent* GetFileDirent(char* path, char* name)
{
	DIR* dirp = OpenDirectory(path);
	struct dirent* dp;
	if(NULL == dirp) return NULL;
	do {
		errno = 0;
		if ((dp = ReadDirectory(dirp)) != NULL) 
		{
			if (strcmp(dp->d_name, name) == 0)
			{
				CloseDirectory(dirp);
				return dp;
			}	
		}	
	} while (dp != NULL);

	if (errno != 0)
	{
		fprintf(stderr, "Error while searching for file %s in directory %s\n", name, path);
		fprintf(stderr, "Error = %s\n", strerror(errno));
	}
	CloseDirectory(dirp);
	return NULL;
}
 // This takes all the names of all the files in the directory given by
 // inputDirectory which end in inputSuffix, and places each in a
 // FilenameTriple with the placeholder filename given by replacing
 // inputSuffix with placeholderSuffix, replacing the directory path with
 // placeholderDirectory, and the same for the output file using
 // outputSuffix and outputDirectory.
 inline void
 FilePlaceholderManager::PrepareFilenames( std::string const& inputDirectory,
                                      std::string const& placeholderDirectory,
                                          std::string const& outputDirectory )
 {
   std::vector< std::string > validBaseFilenames;
   OpenDirectory( inputDirectory );
   while( ReadNextFilenameInDirectory() )
   {
     if( currentFilename.compare( ( currentFilename.size()
                                    - inputSuffix.size() ),
                                  inputSuffix.size(),
                                  inputSuffix ) == 0 )
     {
       validBaseFilenames.push_back( currentFilename.substr( 0,
                          ( currentFilename.size() - inputSuffix.size() ) ) );
     }
   }
   PrepareFilenames( validBaseFilenames,
                     inputDirectory,
                     placeholderDirectory,
                     outputDirectory );
   CloseDirectory();
 }
예제 #3
0
QDirectory::~QDirectory()
{
	CloseDirectory();
}
 ~FilePlaceholderManager() { CloseDirectory(); }