Article # 177, added by Geoworks, historical record
| first |
previous |
index |
next |
last |
Deleting all files ("del *.*") with FileEnum & FileDelete
There is no routine that deletes all files in a given folder. What you need to do it use FileEnum to return a list of files and delete each file in the list. Here is the basic setup you need to do: /* Put the MatchAttrs in a data resource */ @start FileEnumMatchAttrs, data; @chunk FileExtAttrDesc MatchAttrs[] = { { FEA_FILE_TYPE, (void *)0, /* this will be filled in later */ sizeof( GeodeToken ), NULL }, { FEA_END_OF_LIST, 0, 0, NULL } }; @chunk GeosFileType fileTypes = (GFT_NOT_GEOS_FILE | GFT_EXECUTABLE | GFT_VM | GFT_DATA); @end FileEnumMatchAttrs; /* The routine to find and delete the files should look something like * this: */ MyFileDeleteAll() { FileExtAttrDesc *attrsToMatch; FileEnumParams fileEnumParams; MemHandle fileNameListHandle; word filesNotHandled; TCHAR * fileNameListPtr; /* * first set up the attribute for FileEnum to match. In this * case, I am use the document's creator, which will be the * GeodeToken of your geode. */ MemLock(OptrToHandle(@MatchAttrs)); attrsToMatch = LMemDeref(@MatchAttrs); attrsToMatch->FEAD_value = LMemDeref(@fileTypes); /* * Set the search flags to search all files, but not directories. * (FILE_ENUM_ALL_FILE_TYPES does not include FESF_DIRS). */ fileEnumParams.FEP_searchFlags = FILE_ENUM_ALL_FILE_TYPES /* * Return the file's Geos filename. FE_BUFSIZE_UNLIMITED * allows the return buffer size to be as large as necessary. */ fileEnumParams.FEP_returnAttrs = (void *) FESRT_NAME; fileEnumParams.FEP_returnSize = FILE_LONGNAME_BUFFER_SIZE; fileEnumParams.FEP_bufSize = FE_BUFSIZE_UNLIMITED; /* * Set matchAttrs to zero so it will match anything. * Don't skip any files * Don't need a callback. * */ fileEnumParams.FEP_matchAttrs = 0; fileEnumParams.FEP_skipCount = 0; fileEnumParams.FEP_callback = 0; numOfFiles = FileEnum( &fileEnumParams, &fileNameListHandle, &filesNotHandled ); MemLock(OptrToHandle(@MatchAttrs)); /* * Delete all the files in the list returned by FileEnum. * First check to see if any files where found and the buffer * was successfully created (fileNameListHandle will be * NullHandle, which is zero, the buffer couldn't be created). */ if ( numOfFiles && fileNameListHandle ) { fileNameListPtr = MemLock(fileNameListHandle); while(numOfFiles--) { FileDelete(fileNameListPtr); fileNameListPtr += FILE_LONGNAME_BUFFER_SIZE; } MemUnlock(fileNameListHandle); } }