Jump to content

FileFindNextFile


Recommended Posts

The OS puts some files and directories into the root of a drive for it's own use. You would be better IMO to create a Desktop folder in the root of the drive e.g. "E:\Desktop", rather then running into these issues. Anyway, I will address your issue. Use ContinueLoop when you find these files so further processing within the loop is not done.

Some changes which should skip some of the systems folders/files.

If FileExists(@ProgramFilesDir & "\System\poweroff.exe") Then
    $search = FileFindFirstFile("E:\*.*")

    If $search = -1 Then

        $computerafsluiten = MsgBox(4, "Computer afsluiten", "Computer shutdown?", 30)
        If $computerafsluiten = 6 Then
            Sleep(1500)
            Run(@ProgramFilesDir & "\System\poweroff.exe shutdown -force")
        Else
            ;FileClose($search) ;you failed to get a handle initially
            Exit
        EndIf
    Else

        ; Displays: System Volume Information
        While 1
            $file = FileFindNextFile($search)
            If @error Then ExitLoop
            ;check if a directory
            If StringInStr(FileGetAttrib($file), 'D') Then
                Switch $file
                    Case '$RECYCLE.BIN', 'System Volume Information', 'RECYCLER', 'Config.Msi'
                        ContinueLoop
                EndSwitch
            Else
                Switch $file
                    Case 'AUTOEXEC.BAT', 'CONFIG.SYS', 'IO.SYS', 'MSDOS.SYS'
                        ContinueLoop
                EndSwitch
            EndIf
            MsgBox(4096, "File:", $file)
        WEnd
        FileClose($search) ;close the handle when finished with it

        $computerafsluiten = MsgBox(4, "Computer afsluiten", "Computer shutdown (All files will be deleted!)")
        If $computerafsluiten = 6 Then
            DirRemove("E:\", 1);removing a drive?
            FileDelete("E:\*.*");not sure if safe in root of drive
            Sleep(1500)
            Run(@ProgramFilesDir & "\System\poweroff.exe shutdown -force")
        Else
            Exit
        EndIf
    EndIf
Else
    MsgBox(48, "Error", "Poweroff bestaat niet, neem contact op met systeembeheer", 0)
EndIf

That may help to see the concept hopefully

:)

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...