Sign in to follow this  
Followers 0
Necromorph

wildcard fileopen

19 posts in this topic

well, im not sure why this doesn't work

$installserver=FILEFINDFIRSTFILE("C:\test-*.exe")
$packageserver=FILEFINDNEXTFILE($installserver)
FILECLOSE($installserver)
$dest=@DESKTOPDIR & "copytest-*.exe"

$FileCopy = _CopyWithProgress($packageserver, $dest, 5120)

and later

Func _CopyWithProgress($inSource, $inDest, $ChunkSize = 5120)
    $SourceFile = FileOpen($inSource, 16)
    If $SourceFile = -1 Then
        MsgBox(16, "Error", "Unable to open source file: " & $inSource)
        Exit
    EndIf
    
    $DestFile = FileOpen($inDest, 26)
    If $SourceFile = -1 Then
        MsgBox(16, "Error", "Unable to open destination file: " & $inDest)
        Exit
    EndIf

    $SourceSize = FileGetSize($inSource)

    $Chunks = $SourceSize / $ChunkSize

    ProgressOn("File Copy", "Copying...", "Source: " & $inSource & @LF & "Dest:  " & $inDest)

    For $i = 0 to $Chunks
        $Data = FileRead($SourceFile, $ChunkSize)
        FileWrite($DestFile, $Data)
        ProgressSet( (($i + 1) / $Chunks) * 100 )
    Next
    
    ProgressOff()
    FileClose($SourceFile)
    FileClose($DestFile)

    $DestSize = FileGetSize($inDest)

    If $SourceSize = $DestSize Then
        Return 0
    Else
        Return 1
    EndIf
EndFunc

but it says it can't open the sorcefile. is there something special i have to do because its an .exe or does this func just not support wildcards?

thanks a lot

Share this post


Link to post
Share on other sites



redLabel,

What are the actual values of the 2 variables $inSource and $inDest that you pass to the _CopyWithProgress function?

You can find out by adding this line to the beginning of the function:

ConsoleWrite($inSource & " - " & $inDest & @CRLF)

and the values will appear in the lower SciTE window. :mellow:

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

#3 ·  Posted (edited)

it didn't output anything, but im quite sure the wildcards are being found because the msgbox does show and it locates the right file ie: "cannot open sourcefile 'test-25.exe'"

so, im not sure.

one other thing, if the file exists in the dest. then it will work, but doest overwirte it

Edited by redLabel

Share this post


Link to post
Share on other sites

redLabel,

Did the MsgBox really show the single quotes around the filename?

cannot open sourcefile 'test-25.exe'

Because if so, then there is little wonder that the function cannot find the file as AutoIt thinks they are part of the file name.

So we turn to how you get the $packageserver variable to pass to the function in the first place. We spoke about looking for files with FileFindFirst/NextFile - it is not how you should do it. Perhaps you might want to look again at the thread where we discussed it.

Could you please use a MsgBox to see what value you have in the $packageserver variable when you call the _CopyWithProgress function.

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

no there isn't '' around the $packageserver var, i did use a msgbox, and it is finding the proper value ie: test-25.exe

so i don't think it is a problem with the variable. it just seems to be with the fileopen (wildcard), in the mean time i will look up the older post

thank you for helping.

Share this post


Link to post
Share on other sites

still not having any luck, and i don't get it. becuase my msgbox for the error "cannot open source file: $installerpackage", returns the right name of the installer, so there $var are fine, it just won't open it if its a wild card.

Share this post


Link to post
Share on other sites

Maybe try something like:

$installserver=FILEFINDFIRSTFILE("C:\test-*.exe")
$packageserver=FILEFINDNEXTFILE($installserver)
FILECLOSE($installserver)
$dest=@DESKTOPDIR & "\copy"&$packageserver)

$FileCopy = _CopyWithProgress($packageserver, $dest, 5120)

I believe that @desktopdir does not have a trailing backslash which needs to be added between that and filename.

also, since the destination file name was simply your original file name plus copy at the front, I removed the wildcard by combining the word "copy" with the original filename variable.


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

Thanks much for your reply, but that didn't help any, it seems to have problems opening the file for reading after i make it a $var. if i name it specifically it works, but the file will be changing on a regular basis so i want to use a wildcard. so im not sure why once i change it to a wild card it fails to open. but im about ready to just say heck with it. lol. thanks for you help.

Share this post


Link to post
Share on other sites

will your file to copy always be in the same directory? if so you could always use _fillisttoarray which accepts wildcards.


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

yeah, it will always copy to the desktop, and it will always be copying from the same place as well. i will look into it. ive never used that, so i will see if i can get it to work. thanks.

Share this post


Link to post
Share on other sites

well, bad news, i got the array to work, i can msgbox out the right installer, but same thing. says it cannot read from it, i a have about had it.

Share this post


Link to post
Share on other sites

You are not making any sense.

What about you try to ask explicit questions in stead of the general " it doesn't work" ... you might get real help.


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

why can't i do my above func (1st post) when i use a wild card for the file i want to copy.

#Include <File.au3>
#Include <Array.au3>
$FileList=_FileListToArray("\\TESTSHARE\DIR\TEST", "TESTINSTALLER-*.exe", 1)

$FileCopy = _CopyWithProgress($FileList[1], "C:\"& $FileList, 5120)

If $FileCopy = 0 Then
    PROGRESSOFF()
    EXIT
Else
    MsgBox(16,"Copy Complete", "File Copy Failed.")
EndIf



Func _CopyWithProgress($inSource, $inDest, $ChunkSize = 5120)
    $SourceFile = FileOpen($inSource, 32)
    If $SourceFile = -1 Then
        MsgBox(16, "Error", "Unable to open source file: " & $inSource)
        Exit
    EndIf
    
    $DestFile = FileOpen($inDest, 26)
    If $SourceFile = -1 Then
        MsgBox(16, "Error", "Unable to open destination file: " & $inDest)
        Exit
    EndIf

    $SourceSize = FileGetSize($inSource)

    $Chunks = $SourceSize / $ChunkSize

    ProgressOn("File Copy", "Copying...", "Source: " & $inSource & @LF & "Dest:  " & $inDest)

    For $i = 0 to $Chunks
        $Data = FileRead($SourceFile, $ChunkSize)
        FileWrite($DestFile, $Data)
        ProgressSet( (($i + 1) / $Chunks) * 100 )
    Next
    
    FileClose($SourceFile)
    FileClose($DestFile)

    $DestSize = FileGetSize($inDest)

    If $SourceSize = $DestSize Then
        Return 0
    Else
        Return 1
    EndIf
EndFunc

i can't get it to open the source file, i get my own msg box

$SourceFile = FileOpen($inSource, 32)
    If $SourceFile = -1 Then
        MsgBox(16, "Error", "Unable to open source file: " & $inSource)
        Exit
    EndIf

but this only happens when i use a wildcard for the .exe im copying. if i specify the exact folder and don't use $var for the $FileCopy, it works. if i use my method with the array, and msgbox out the result for $FileList[1] it find the right installer, so its not a problem with the $var's it just when they are = wildcards.

that is my specific ?.

sorry if im just missing something stupid.

Edited by redLabel

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

and tells me that it cannot open the source file: testinstaller-0.25.exe. it finds the file. the $vars are working and so is the array, but it can't open the file. and i cannot figure out why, is it because the file is "open" in some other way in my script? like i said if i don't use $vars and just give a dir and dest it works, but the msg box returns the correct value for the $var so it is finding it, but why can't it open it?

Edited by redLabel

Share this post


Link to post
Share on other sites

and tells me that it cannot open the source file: testinstaller-0.25.exe. it finds the file. the $vars are working and so is the array, but it can't open the file. and i cannot figure out why, is it because the file is "open" in some other way in my script? like i said if i don't use $vars and just give a dir and dest it works, but the msg box returns the correct value for the $var so it is finding it, but why can't it open it?

Hey com'on... think!

why would it know where that file lives?

Where did you tell it its directory?

What do you think the directory is where it is trying to find it?


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

HAHAHAHAH! I cannot believe im so stupid. i was getting the NAME of the installer, but couldn't open it because it still couldn't find it. thank you very much

#Include <File.au3>
#Include <Array.au3>
$FileList=_FileListToArray("C:\", "test-*.exe", 1)

$FileCopy = _CopyWithProgress("C:\"& $FileList[1], "C:\test\"& $FileList[1], 5120)

thanks agian

Share this post


Link to post
Share on other sites

HAHAHAHAH! I cannot believe im so stupid. i was getting the NAME of the installer, but couldn't open it because it still couldn't find it. thank you very much

Seriously: I have not told you anything new. Just reread this thread and see that you already got the answer in the very first reply from Melba23.

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

yeah, im sure that this was dragged out much much longer then needed. but when it would msgbox out the right name of the .exe i was looking for, i thought for sure the code was right, so sorry again for wasting time. and thanks for helping me solve the issue.

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