Borje Posted August 5, 2007 Share Posted August 5, 2007 (edited) I am total newbe here but I need some help with a command. My question is what must I have for command to deletes all files and folders in examle folder c:\Documents and settings\user\Favorites I have try to delete this folder but that not works it is a system folder. Please all you experts help me... Anoter question: What must i Use for command if I want to have a progress window to display the deletes files and folders in c:\Documents and settings\user\Favorites ? Edited August 5, 2007 by Borje Link to comment Share on other sites More sharing options...
Gif Posted August 5, 2007 Share Posted August 5, 2007 (edited) I am total newbe here but I need some help with a command. My question is what must I have for command to deletes all files in examle folder c:\Documents and settings\user\Favorites I have try to delete this folder but that not works it is a system folder. Please all you experts help me... Anoter question: What must i Use for command if I want to have a progress window to display the deletes files? try to unset the system attribute of the folder: FileSetAttrib('C:\Documents and settings\user\Favorites', '-S') DirRemove('C:\Documents and settings\user\Favorites') Exit PS: look at ProgressOn() , ProgressOff() and ProgressSet() Edited August 5, 2007 by Gif Link to comment Share on other sites More sharing options...
Borje Posted August 5, 2007 Author Share Posted August 5, 2007 try to unset the system attribute of the folder: FileSetAttrib('C:\Documents and settings\user\Favorites', '-S') FileDelete('C:\Documents and settings\user\Favorites') Exit PS: look at ProgressOn() , ProgressOff() and ProgressSet() Thanks alot i be tested this Link to comment Share on other sites More sharing options...
MHz Posted August 5, 2007 Share Posted August 5, 2007 (edited) Use Attrib using Run() and @Comspec as AutoIt only does files using FileSetAttrib().Edit:ExampleRunWait(@ComSpec & ' /c Attrib -s "' & @FavoritesDir & '"') Edited August 5, 2007 by MHz Link to comment Share on other sites More sharing options...
Borje Posted August 5, 2007 Author Share Posted August 5, 2007 Hello MHZ I test this but it not works I can not delete the files i favorites folder Link to comment Share on other sites More sharing options...
MHz Posted August 5, 2007 Share Posted August 5, 2007 Hello MHZ I test this but it not works I can not delete the files i favorites folderI concentrated on the attribute of the folder only. Try this UDF for cleaning out your favorites folder. _CleanFolder(@FavoritesDir) If @error Then MsgBox(0, '', 'Parameter passed is not a folder') EndIf Func _CleanFolder($fullpath) If Not StringInStr(FileGetAttrib($fullpath), 'D') Then Return SetError(1, 0, '') EndIf $handle_search = FileFindFirstFile($fullpath & '\*') If $handle_search <> -1 Then While 1 $file_found = FileFindNextFile($handle_search) If @error Then ExitLoop EndIf If StringInStr(FileGetAttrib($fullpath & '\' & $file_found), 'D') Then DirRemove($fullpath & '\' & $file_found, 1) Else FileDelete($fullpath & '\' & $file_found) EndIf WEnd FileClose($handle_search) EndIf EndFunc Link to comment Share on other sites More sharing options...
Borje Posted August 5, 2007 Author Share Posted August 5, 2007 Hi MHZ Thanks it works now you muste be a expert of this Many thanks If any body have some tips about this write them here I would like to learn so much I can. Link to comment Share on other sites More sharing options...
Borje Posted August 5, 2007 Author Share Posted August 5, 2007 _CleanFolder(@FavoritesDir) If @error Then MsgBox(0, '', 'Parameter passed is not a folder') EndIf Func _CleanFolder($fullpath) If Not StringInStr(FileGetAttrib($fullpath), 'D') Then Return SetError(1, 0, '') EndIf $handle_search = FileFindFirstFile($fullpath & '\*') If $handle_search <> -1 Then While 1 $file_found = FileFindNextFile($handle_search) If @error Then ExitLoop EndIf If StringInStr(FileGetAttrib($fullpath & '\' & $file_found), 'D') Then DirRemove($fullpath & '\' & $file_found, 1) Else FileDelete($fullpath & '\' & $file_found) EndIf WEnd FileClose($handle_search) EndIf EndFunc What must be changed in the code to have a progress window that displays the deletes files and folders in the Favorites folder? Link to comment Share on other sites More sharing options...
MHz Posted August 5, 2007 Share Posted August 5, 2007 (edited) Give this a try_CleanFolder(@FavoritesDir) If @error Then MsgBox(0, '', 'Parameter passed is not a folder') EndIf Func _CleanFolder($fullpath) Local $dirSize, $file_found, $handle_search, $i = 0 If Not StringInStr(FileGetAttrib($fullpath), 'D') Then Return SetError(1, 0, '') EndIf $dirSize = DirGetSize($fullpath, 1) ProgressOn('Progess', 'Cleaning ' & $fullpath) $handle_search = FileFindFirstFile($fullpath & '\*') If $handle_search <> -1 Then While 1 $file_found = FileFindNextFile($handle_search) If @error Then ExitLoop EndIf If StringInStr(FileGetAttrib($fullpath & '\' & $file_found), 'D') Then DirRemove($fullpath & '\' & $file_found, 1) $i += 1 Else FileDelete($fullpath & '\' & $file_found) EndIf If IsArray($dirSize) And $i <> 0 Then ProgressSet(100 / $dirSize[2] * $i) ElseIf Not IsArray($dirSize) Then ProgressOff() EndIf WEnd FileClose($handle_search) ProgressOff() EndIf EndFuncIt works on the folder count, so if you have just files in your favorites folder then it will not update the progress too well at all.Edit:Code correction done Edited August 5, 2007 by MHz Link to comment Share on other sites More sharing options...
Borje Posted August 5, 2007 Author Share Posted August 5, 2007 Thank you very very much MHZ All works perfect now!! Many tanks Link to comment Share on other sites More sharing options...
MHz Posted August 5, 2007 Share Posted August 5, 2007 (edited) Thank you very very much MHZ All works perfect now!! Many tanksHmmm, not perfect as DirGetSize() does sub folders as well so the progress is incorrect. This will do better. expandcollapse popup_CleanFolder(@FavoritesDir) If @error Then MsgBox(0, '', 'Parameter passed is not a folder') EndIf Func _CleanFolder($fullpath) Local $dirSize, $file_found, $handle_search, $i = 0, $count = 0 If Not StringInStr(FileGetAttrib($fullpath), 'D') Then Return SetError(1, 0, '') EndIf ; Get the amount of file and dirs in the root $handle_search = FileFindFirstFile($fullpath & '\*') If $handle_search <> -1 Then While 1 $file_found = FileFindNextFile($handle_search) If @error Then ExitLoop $count += 1 WEnd FileClose($handle_search) If Not $count Then Return SetError(2, 0, '') EndIf ; Progress through the folder ProgressOn('Progess', 'Cleaning ' & $fullpath) $handle_search = FileFindFirstFile($fullpath & '\*') If $handle_search <> -1 Then While 1 $file_found = FileFindNextFile($handle_search) If @error Then ExitLoop EndIf If StringInStr(FileGetAttrib($fullpath & '\' & $file_found), 'D') Then DirRemove($fullpath & '\' & $file_found, 1) $i += 1 Else FileDelete($fullpath & '\' & $file_found) $i += 1 EndIf ProgressSet(100 / $count * $i) WEnd FileClose($handle_search) ProgressOff() EndIf EndFunc Edited August 5, 2007 by MHz Link to comment Share on other sites More sharing options...
Borje Posted August 5, 2007 Author Share Posted August 5, 2007 Hi again MHZ Thanks for this latest fix you done it works great now..... Link to comment Share on other sites More sharing options...
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