//----------------------------------------------------------------// bool USFileSys::DeleteDirectory ( cc8* path, bool force, bool recursive ) { if ( USFileSys::CheckPathExists ( path ) == false ) return true; int result = zl_rmdir ( path ); if ( result == 0 ) return true; if ( !( force || recursive )) return false; STLString currentDir = USFileSys::GetCurrentPath (); USFileSys::SetCurrentPath ( path ); USDirectoryItr dirItr; if ( force ) { dirItr.Start (); while ( dirItr.NextFile ()) { USFileSys::DeleteFile ( dirItr.Current ()); } } if ( recursive ) { dirItr.Start (); while ( dirItr.NextDirectory ()) { if( strcmp ( dirItr.Current (), ".." ) == 0 || strcmp ( dirItr.Current (), "." ) == 0 ) { continue; } USFileSys::DeleteDirectory ( dirItr.Current (), force, recursive ); } } USFileSys::SetCurrentPath ( currentDir ); return ( zl_rmdir ( path ) == 0 ); }
/** @name listDirectories @text Lists the sub-directories contained in a directory. @opt string path Path to search. Default is current directory. @out table diresctories A table of directory names (or nil if the path is invalid) */ int MOAIFileSystem::_listDirectories ( lua_State* L ) { UNUSED ( L ); STLString oldPath = USFileSys::GetCurrentPath(); cc8* dir = NULL; if ( lua_type ( L, 1 ) == LUA_TSTRING ) { dir = lua_tostring ( L, 1 ); if ( !USFileSys::SetCurrentPath ( dir )) { return 0; } } USDirectoryItr dirItr; lua_newtable ( L ); int n = 0; dirItr.Start (); while ( dirItr.NextDirectory ()) { if ( dir ) { lua_pushstring ( L, dir ); lua_pushstring ( L, "/" ); lua_pushstring ( L, dirItr.Current ()); lua_concat ( L, 3 ); } else { lua_pushstring ( L, dirItr.Current ()); } n++; luaL_setn ( L, -2, n ); // new size lua_rawseti ( L, -2, n ); // t[pos] = v } USFileSys::SetCurrentPath ( oldPath ); return 1; }