Sign in to follow this  
Followers 0
asgarcymed

Trying to convert/translate/adapt a VBS to AU3

5 posts in this topic

The following VBScript is a very easy demonstration how to make a recursive subroutine/function:

CODE
Set fso = CreateObject ("Scripting.FileSystemObject")

pasta_inicial = ("C:\Portable Apps\7-Zip")

Set pasta_obtida = fso.GetFolder(pasta_inicial)

Wscript.Echo pasta_obtida.Path

Set lista_ficheiros = pasta_obtida.Files

For Each ficheiro In lista_ficheiros

Wscript.Echo ficheiro.Name

Next

Wscript.Echo

lista_sub_pastas fso.GetFolder(pasta_inicial)

Sub lista_sub_pastas(pasta)

For Each sub_pasta In pasta.SubFolders

Wscript.Echo sub_pasta.Path

Set pasta_obtida = fso.GetFolder(sub_pasta.Path)

Set lista_ficheiros = pasta_obtida.Files

For Each ficheiro In lista_ficheiros

Wscript.Echo ficheiro.Name

Next

Wscript.Echo

lista_sub_pastas sub_pasta

Next

End Sub

I tried to convert/translate/adapt it, from VBS to AU3....

I did:

Dim $fso, $pasta_inicial, $pasta_obtida, $lista_ficheiros, $ficheiro, $lista_sub_pastas, $sub_pasta

$fso = ObjCreate("Scripting.FileSystemObject")
$pasta_inicial = ("C:\Portable Apps\7-Zip")

$pasta_obtida = $fso.GetFolder ($pasta_inicial)
FileWrite(@DesktopDir & "\log.log", ($pasta_obtida.Path) & Chr(13))
$lista_ficheiros = $pasta_obtida.Files

For $ficheiro In $lista_ficheiros
    FileWrite(@DesktopDir & "\log.log", ($ficheiro.Name) & Chr(13))
Next


$lista_sub_pastas ($fso.GetFolder ($pasta_inicial))

Func lista_sub_pastas($pasta)
    For $sub_pasta In $pasta.SubFolders ()
        FileWrite(@DesktopDir & "\log.log", ($sub_pasta.Path) & Chr(13))
        $pasta_obtida = $fso.GetFolder ($sub_pasta.Path)
        $lista_ficheiros = $pasta_obtida.Files
        For $ficheiro In $lista_ficheiros
            FileWrite(@DesktopDir & "\log.log", ($ficheiro.Name) & Chr(13))
        Next
        $lista_sub_pastas ($sub_pasta)
    Next
EndFunc   ;==>lista_sub_pastas

However I get an error that is putting my brain on fire:

« (15) : ==> Unbalanced brackets in expression »

What is this; what does it mean; why it is happening????

Thanks.

Regards.


MLMK - my blogging craziness...

Share this post


Link to post
Share on other sites

ALL give ERROR:

lista_sub_pastas ($fso.GetFolder ($pasta_inicial))

lista_sub_pastas ($fso.GetFolder $pasta_inicial)

lista_sub_pastas $fso.GetFolder ($pasta_inicial)

lista_sub_pastas $fso.GetFolder $pasta_inicial


MLMK - my blogging craziness...

Share this post


Link to post
Share on other sites

Hello asgarcymed,

I think what Randallc is saying is: remove the '$' from the beginning of your function calls. When I renamed them "lista_sub_pastas", your code works. :P

lista_sub_pastas ( $fso.GetFolder ($pasta_inicial) )

Func lista_sub_pastas($pasta)
    For $sub_pasta In $pasta.SubFolders ()
        FileWrite(@DesktopDir & "\log.log", ($sub_pasta.Path) & Chr(13))
        $pasta_obtida = $fso.GetFolder ($sub_pasta.Path)
        $lista_ficheiros = $pasta_obtida.Files
        For $ficheiro In $lista_ficheiros
            FileWrite(@DesktopDir & "\log.log", ($ficheiro.Name) & Chr(13))
        Next
        lista_sub_pastas ($sub_pasta)
    Next
EndFunc  ;==>lista_sub_pastas

Zach...

Share this post


Link to post
Share on other sites

Finally my brain can rest in peace :P

Thank you a lot!!

Regards.


MLMK - my blogging craziness...

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