Sign in to follow this  
Followers 0
Borje

Help about a command to deletes files in a folder

12 posts in this topic

#1 ·  Posted (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 by Borje

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by Gif

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Use Attrib using Run() and @Comspec as AutoIt only does files using FileSetAttrib().

:)

Edit:

Example

RunWait(@ComSpec & ' /c Attrib -s "' & @FavoritesDir & '"')
Edited by MHz

Share this post


Link to post
Share on other sites

Hello MHZ

I test this but it not works I can not delete the files i favorites folder

Share this post


Link to post
Share on other sites

Hello MHZ

I test this but it not works I can not delete the files i favorites folder

I 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

:)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

_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?

Share this post


Link to post
Share on other sites

#9 ·  Posted (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
EndFunc

It 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 by MHz

Share this post


Link to post
Share on other sites

Thank you very very much MHZ

All works perfect now!!

Many tanks

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Thank you very very much MHZ

All works perfect now!!

Many tanks

Hmmm, not perfect as DirGetSize() does sub folders as well so the progress is incorrect.

This will do better.

_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 by MHz

Share this post


Link to post
Share on other sites

Hi again MHZ

Thanks for this latest fix you done it works great now.....

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0