Sign in to follow this  
Followers 0
TripScott

Script doesn't run when compiled

4 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



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.


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


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

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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