示例#1
0
RCODE FTKAPI F_DirHdl::next( void)
{
	char					szFoundPath[ F_PATH_MAX_SIZE];
	char					szDummyPath[ F_PATH_MAX_SIZE];
	FLMUINT				uiSearchAttributes;
	FLMUINT				uiFoundAttrib;
	IF_FileSystem *	pFileSystem = f_getFileSysPtr();

	if( RC_BAD( m_rc))
	{
		goto Exit;
	}

	uiSearchAttributes =
		F_IO_FA_NORMAL | F_IO_FA_RDONLY | F_IO_FA_ARCHIVE | F_IO_FA_DIRECTORY;

	for( ;;)
	{
		if( m_bFirstTime)
		{
			m_bFirstTime = FALSE;

			if( RC_BAD( m_rc = f_fileFindFirst( m_szDirectoryPath, 
				uiSearchAttributes, &m_FindData, szFoundPath, &uiFoundAttrib)))
			{
				goto Exit;
			}
			
			m_bFindOpen = TRUE;
			m_uiAttrib = uiFoundAttrib;
		}
		else
		{
			if( RC_BAD( m_rc = f_fileFindNext( &m_FindData, 
				szFoundPath, &uiFoundAttrib)))
			{
				goto Exit;
			}
			
			m_uiAttrib = uiFoundAttrib;
		}

		if( RC_BAD( m_rc = pFileSystem->pathReduce( szFoundPath, 
			szDummyPath, m_szFileName)))
		{
			goto Exit;
		}

		if( pFileSystem->doesFileMatch( m_szFileName, m_szPattern))
		{
			break;
		}
	}

Exit:

	return( m_rc);
}
示例#2
0
RCODE FTKAPI F_DirHdl::createDir(
	const char *	pszDirPath)
{
	RCODE					rc = NE_FLM_OK;
	char *				pszParentDir = NULL;
	IF_FileSystem *	pFileSystem = f_getFileSysPtr();

	if( RC_BAD( rc = f_alloc( F_PATH_MAX_SIZE, &pszParentDir)))
	{
		goto Exit;
	}

	// Discover the parent directory of the given one

	if( RC_BAD( rc = pFileSystem->pathReduce( pszDirPath, 
		pszParentDir, NULL)))
	{
		goto Exit;
	}

	// If pathReduce couldn't reduce the path at all, then an
	// invalid path was supplied.

	if( f_strcmp( pszDirPath, pszParentDir) == 0)
	{
		rc = RC_SET( NE_FLM_IO_INVALID_FILENAME);
		goto Exit;
	}

	// If a parent directory was found, and it doesn't already exist, create it

	if( *pszParentDir)
	{
		// If the "parent" is actually a regular file we need to return an error

		if( RC_OK( pFileSystem->doesFileExist( pszParentDir)))
		{
			if( !pFileSystem->isDir( pszParentDir))
			{
				rc = RC_SET( NE_FLM_IO_ACCESS_DENIED);
				goto Exit;
			}
		}
		else if( RC_BAD( rc = createDir( pszParentDir)))
		{
			goto Exit;
		}
	}

#if defined( FLM_WIN)

	if( !CreateDirectory((LPTSTR)pszDirPath, NULL))
	{
		rc = f_mapPlatformError( GetLastError(), NE_FLM_CREATING_FILE);
	}

#elif defined( FLM_UNIX) || defined( FLM_LIBC_NLM)

	if( mkdir( (char *)pszDirPath, 0777) == -1)
	{
		rc = f_mapPlatformError( errno, NE_FLM_CREATING_FILE);
	}

#endif

Exit:

	if( pszParentDir)
	{
		f_free( &pszParentDir);
	}
	
	return( rc);
}