Jump to content

Help about a command to deletes files in a folder


 Share

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
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

:)

Link to comment
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?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...