Guest prsobel Posted May 24, 2005 Posted May 24, 2005 Might someone provide the syntax for removing the contents, files and subdirectories, of the Favorites folder located at D:\Relocated System Stuff\Favorites? The intent is to keep the folder, but to remove its contents. Thank you.
MHz Posted May 24, 2005 Posted May 24, 2005 Use this code: ; Shows the filenames of all files in the current directory, note that "." and ".." are returned. $location = "D:\Relocated System Stuff\Favorites\" $search = FileFindFirstFile($location & "*.*") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If $file = "." Or $file = ".." Then ContinueLoop If Not DirRemove($location & $file, 1) Then FileDelete($location & $file) WEnd ; Close the search handle FileClose($search)
Guest prsobel Posted May 24, 2005 Posted May 24, 2005 Thank you very much. It turns out that the DirRemoveContents function is no longer available. Because the Favorites folder is a "system" folder it cannot be deleted, merely emptied and refilled. Might it be possible to change the Favorites folder's attributes from "system," replace it and then reassign the "system" attribute? I tried using FileSetAttrib without success. In any event, thank you for your assistance.
eJan Posted June 11, 2005 Posted June 11, 2005 To have empty Favorites with _DirRemoveContents use:$Dir = @FavoritesDir _DirRemoveContents($Dir) MsgBox(262144, "Complete", "Favorites cleaned") Func _DirRemoveContents($sPath) Local $sPattern Local $sFile Local $hFile If StringRight($sPath, 1) <> "\" Then $sPath = $sPath & "\" $sPattern = $sPath & "*.*" If Not FileExists($sPath) Then Return 0 FileDelete($sPattern) $hFile = FileFindFirstFile($sPattern) If @error Then Return 0 While 1 $sFile = FileFindNextFile($hFile) If @error Then ExitLoop If $sFile <> "." And $sFile <> ".." Then If StringInStr( FileGetAttrib($sPath & $sFile), "D") Then DirRemove($sPath & $sFile, 1) EndIf EndIf WEnd FileClose($hFile) Return 1 EndFunc
Groumphy Posted June 11, 2005 Posted June 11, 2005 Thank you very much. It turns out that the DirRemoveContents function is no longer available.I think that the function of eJan is easier... Because easily reusable. It is simply necessary to personalize the variable of directory. ----------------------GroumphyMore information about me [Fr]
Groumphy Posted June 11, 2005 Posted June 11, 2005 Why not to also test : Func _RemoveDirContents2($iDir) ; success : 1 ; failure : 0 Dim $iPath Local $iPath $iDir = $iPath Return DirRemove($iDir, 1); Delete the directory and all contents Return DirCreate($iPath); Create the directory (empty) EndFunc; ==> _RemoveDirContents2("C:\test") ???? ----------------------GroumphyMore information about me [Fr]
/dev/null Posted June 11, 2005 Posted June 11, 2005 (edited) ????why do you need $iPath???EDIT: Also. return DirRemove will alway end the function, without calling DirCreate.CheersKurt Edited June 11, 2005 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
Groumphy Posted June 11, 2005 Posted June 11, 2005 why do you need $iPath??? :"> a mistake EDIT: Also. return DirRemove will alway end the function, without calling DirCreate. Grrrrrr... ----------------------GroumphyMore information about me [Fr]
/dev/null Posted June 11, 2005 Posted June 11, 2005 Grrrrrr...sorry ... CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
Groumphy Posted June 11, 2005 Posted June 11, 2005 (edited) It is not against you I'm sulky but again my script (I don't test it). Why not try a function who call on other function (function in a function) same of hereWriting quickly and not tested : Func _GlobaleFileRemoveContents2($iPath) Func _FileRemoveContents2($iPath) Return FileDelete($iPath & "\*.*") EndFunc Local _FileRemoveContents2($iPath) Return DirCreate($iPath) EndFunc... Edited June 11, 2005 by Groumphy ----------------------GroumphyMore information about me [Fr]
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now