Jump to content

whats wrong with this script


Recommended Posts

Can anyone tell me why MOST of the time im getting a message saying i have too many subscript or range is exceeded even though i have 'if not @ error then'

it happens at lines:

9.DirRemove("C:\Test1\" & $Dir[$num], 1)--------------------------->happens if no folders exist

____________________________^Array too many or too high

18.FileDelete("C:\Test1\" & $Dir2[$num2])----------------------------->happens after creating a folder in the directory

_____________________________^Array too many or too high

Pictures at bottom

CODE
#include <File.au3>

While 1

$Dir=_FileListToArray ( "C:\Test1" , "*", 2)

If not @error Then

$num=1

Do

DirRemove("C:\Test1\" & $Dir[$num], 1)

$num=$num+1

until $num=$Dir[0]+1

EndIf

$Dir2=_FileListToArray ( "C:\Test1" , "*", 1)

If not @error Then

$num2=1

Do

FileDelete("C:\Test1\" & $Dir2[$num2])

$num2=$num2+1

until $num2=$Dir2[0]+1

EndIf

Wend

PS: It's even worse without do...until because there needs to be "# of folders=# of files" which is almost impossible

Posted Image

Posted Image

Edited by nonplayablecharacter

You can always count on me for the dumb questions ;)My Scripts:Rikku

Link to comment
Share on other sites

I'm not sure why you have all of this in a While loop, but thats beside the point. Ever used a For...To... loop?

#include <File.au3>

While 1
    $arDirs = _FileListToArray ( "C:\Test1" , "*", 2)
    If Not @error Then
        For $i=1 To $arDirs[0]
            DirRemove("C:\Test1\" & $arDirs[$i], 1)
        Next
    EndIf
    
    $arFiles = _FileListToArray ( "C:\Test1" , "*", 1)
    If Not @error Then
        For $i=1 To $arFiles[0]
            FileDelete("C:\Test1\" & $Dir2[$i])
        Next
    EndIf
Wend
Link to comment
Share on other sites

maybe....

#include <File.au3>

$Location = @ScriptDir & "\" ; "C:\Test1"

$Dir = _FileListToArray($Location, "*", 2)

For $x = 1 To $Dir[0]
    
    $Files = _FileListToArray($Location & $Dir[$x] & "\", "*", 1)

    For $i = 1 To $Files[0]
        ;FileDelete($Location & $Dir[$x] & "\" & $Files[$i])
        ConsoleWrite("deleted file - " & $Location & $Dir[$x] & "\" & $Files[$i] & @CRLF)
    Next
    
    ;DirRemove($Location & $Dir[$num], 1)
    ConsoleWrite("> dir removed - " & $Location & $Dir[$x] & @CRLF)
Next

you have to remove the files first AFAIK..

8)

NEWHeader1.png

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