Jump to content

Script doesn't run when compiled


Recommended Posts

When I run this code in SciTE it works perfectly. However, once it is compiled it gives an @error code 5 -- file not found. It isn't picking up the subfolder that the zip file is in. Anyone know why this is happening and how to fix it? I am running AutoIt 3.3.6.1.

#include <File.au3>
#include <Zip.au3>
#include <Array.au3>
Dim $myFolder

$sRoot = 'C:\data\pimvault'
$sFile = '*.zip'

Func _FindFile($sRoot, $sFile)
    If FileExists($sRoot & '\' & $sFile) Then
        Return $sRoot
    EndIf
    Local $Result = '', $FileList = _FileListToArray($sRoot, '*', 2)

    If Not @error Then
        For $i = 1 To $FileList[0]
            $Result = _FindFile($sRoot & '\' & $FileList[$i], $sFile)
            $myFolder = $FileList[$i]
            If Not @error Then
                ExitLoop
            EndIf
        Next
    EndIf
    Return SetError(($Result = ''), 0, $Result)
EndFunc   ;==>_FindFile

$find = _FindFile($sRoot, $sFile)
$sZipFile = "C:\data\pimvault\" & $myFolder & "\" & $myFolder & ".zip"
$sFileName = "C:\data\ProductView\" & $myFolder & "REF.edz"


$sZip = _Zip_AddItem($sZipFile, $sFileName, "", 1)
Edited by TripScott
Link to comment
Share on other sites

  • Moderators

TripScott,

You declare $myFolder but leave it empty. You then use that empty variable to declare both $sZipFile and $sFileName - which you then pass to the UDF. Why are you surprised that the UDF cannot then find the file, given that both parameters are likely to be complete nonsense? :blink:

Did you actually check what you were passing as parameters - always a good idea if you get an error from a UDF! ;)

M23

Hint: You need to look again at the name of the variable you use to capture the return value of the _FindFile function.

P.S. And do not forget to error check what that ugly recursive :P function gives you either.

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I am trying to get the name of the subfolder. This function is the only thing I can find that does it, however, not when compiled. What I really want is to get the name of the subfolder as a variable so I can use it in the zip function. Is there an easier way?

Link to comment
Share on other sites

  • Moderators

TripScott,

Oops! Ignore everything I posted above, I was having a "senior moment" - $myFolder is of course Global and so is set by the function. :blink:

Top Tip: Much better coding practice to use Global/Local instead of Dim to make the scope explicit. ;)

However, that search function of yours is not optimal - it seems to set $myFolder to the last searched folder in the "not found" case. That would explain why you get the "file not found" error. :P

There are plenty of much better recursive file search scripts out there (most of which do not use recursion either!) - if I were you I would go and find a better one.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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