Jump to content

[Solved] FileFindNextFile grabbing unintended file


EmilyLove
 Share

Recommended Posts

So here's my code.

I am downloading a file using chrome (because inetget doesnt work). I want my code to move the file elsewhere when it is done downloading.

$Drive="C:\"
Do
    $hVipre = FileFindFirstFile(@UserProfileDir & "\Downloads\VIPRERescue*")
    Do
        $Vipre = FileFindNextFile($hVipre)
        If @error = 1 Then
            FileClose($hVipre)
            $Vipre = ""
            ExitLoop
        EndIf
    Until @error <> 1 AND $Vipre <> ""
Until FileExists(@UserProfileDir & "\Downloads\" & $Vipre) = 1
FileMove(@UserProfileDir & "\Downloads\" & $Vipre, $Drive & "PortableApps\VIPRERescuePortable\App\VIPRERescue\VIPRERescue.exe", 1)

It tries to move a file that is still downloading and thus causes problems. I'm fairly new to searching files so any help would be greatly appreciated.

~Jeff

Edited by BetaLeaf
Solution at https://www.autoitscript.com/forum/topic/184663-solved-filefindnextfile-grabbing-unintended-file/?do=findComment&comment=1326452

 

 

Link to comment
Share on other sites

Wait till the file is a certain size.  If you can send the file size from Chrome, then you can move when the file is that size.  Another good way if you cannot get the file size from Chrome, is to detect the file and note it's size.  If the file stays the same size for like 40 seconds or something then you can assume the file is ready to be moved.  If the file size changes reset the counter.

I've done this with FTP but not Chrome

Edited by Xandy
Link to comment
Share on other sites

That was weird. I was quoting Xandy but when I submitted the post, instead of posting what I actually typed, it put what I post last, resulting in a duplicate double post. I've never seen any forum do this before. New Feature? lol.

4 hours ago, PACaleala said:

 

Edited by BetaLeaf

 

 

Link to comment
Share on other sites

5 hours ago, Xandy said:

Wait till the file is a certain size.  If you can send the file size from Chrome, then you can move when the file is that size.  Another good way if you cannot get the file size from Chrome, is to detect the file and note it's size.  If the file stays the same size for like 40 seconds or something then you can assume the file is ready to be moved.  If the file size changes reset the counter.

I've done this with FTP but not Chrome

 

Unfortunately, I don't this this would help. The script is grabbing files like "Unconfirmed 868445.crdownload", which are undownloaded files. They don't even match the search string. What's going on here? I only want the completed files im searching for.

 

 

Link to comment
Share on other sites

#include <MsgBoxConstants.au3>

Local $sSearchDir = @UserProfileDir & "\Downloads\VIPRERescue.exe"
Local $sSearchFile = "VIPRERescue.exe"

Local $sFileName, $hSearch
Do
    $hSearch = FileFindFirstFile ($sSearchDir & $sSearchFile)
    $sFileName = FileFindNextFile ($hSearch)
    Sleep (500)
Until $sFileName = $sSearchFile
FileClose ($hSearch)

Local $iResult = MsgBox (BitOR($MB_SYSTEMMODAL, $MB_OK), "Download complete", "File: " & $sFileName)

If the filename always is "VIPRERescue.exe" something like the code above would work. edit: Perhaps FileClose() should go in the Do / Until loop. I overlooked that. 

Edited by pluto41
Link to comment
Share on other sites

#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

Local $sSearchDir = @UserProfileDir & "\Downloads\VIPRERescue*"

Local $sFileName, $hSearch
Do
    $hSearch = FileFindFirstFile ($sSearchDir)
    $sFileName = FileFindNextFile ($hSearch)
    FileClose ($hSearch)
    Sleep (500)
Until StringRegExp ( $sFileName, '(?i)VIPRERescue\d+.exe', $STR_REGEXPMATCH ) ; Find VIPRERescue / Number / .exe

Local $iResult = MsgBox (BitOR($MB_SYSTEMMODAL, $MB_OK), "Download complete", "File: " & $sFileName)

Then Something like this? Added StringRegExp () Function.

Link to comment
Share on other sites

8 minutes ago, pluto41 said:
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

Local $sSearchDir = @UserProfileDir & "\Downloads\VIPRERescue*"

Local $sFileName, $hSearch
Do
    $hSearch = FileFindFirstFile ($sSearchDir)
    $sFileName = FileFindNextFile ($hSearch)
    FileClose ($hSearch)
    Sleep (500)
Until StringRegExp ( $sFileName, '(?i)VIPRERescue\d+.exe', $STR_REGEXPMATCH ) ; Find VIPRERescue / Number / .exe

Local $iResult = MsgBox (BitOR($MB_SYSTEMMODAL, $MB_OK), "Download complete", "File: " & $sFileName)

Then Something like this? Added StringRegExp () Function.

 
 
 

I'm terrible with regular expressions. I changed my code to this but it is still grabbing incompleted files.

Do
    $hVipre = FileFindFirstFile(@UserProfileDir & "\Downloads\VIPRERescue*.exe")
    Do
        $Vipre = FileFindNextFile($hVipre)
        If @error = 1 Then
            FileClose($hVipre)
            $Vipre = ""
            ExitLoop
        EndIf
    Until stringRegExp($Vipre,'(?i)VIPRERescue\d+.exe',$STR_REGEXPMATCH) = 1
Until FileExists(@UserProfileDir & "\Downloads\" & $Vipre) = 1
ConsoleWrite("Moving VipreRescue" & @CRLF)
FileMove(@UserProfileDir & "\Downloads\" & $Vipre, $Drive & "PortableApps\VIPRERescuePortable\App\VIPRERescue\VIPRERescue.exe", 1)

There is something wrong with my FileFindNextFile Loop. It is escaping the loop when it detects something I didn't search for. It should only escape the loop when it finds the completed file, something I am searching for.

 

 

Link to comment
Share on other sites

#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

Local $sSearchDir = @UserProfileDir & "\Downloads\VIPRERescue*"
;Local $sSearchDir = "C:\Temp\Downloads\VIPRERescue*"

Local $Drive = "C:\"
do
    $hVipre = FileFindFirstFile($sSearchDir)
    Do
        $Vipre = FileFindNextFile($hVipre)
        If @Error Then Exitloop
    Until StringRegExp ( $Vipre, '(?i)VIPRERescue\d+.exe', $STR_REGEXPMATCH )
Until StringRegExp ( $Vipre, '(?i)VIPRERescue\d+.exe', $STR_REGEXPMATCH )
ConsoleWrite("Moving VipreRescue" & @CRLF)
FileClose ($hVipre)
FileMove(@UserProfileDir & "\Downloads\" & $Vipre, $Drive & "PortableApps\VIPRERescuePortable\App\VIPRERescue\VIPRERescue.exe", 1)

This works for me in a test [c:\temp\..]. I think you are close to a solution for the problem.

Link to comment
Share on other sites

Link to comment
Share on other sites

30 minutes ago, pluto41 said:
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

Local $sSearchDir = @UserProfileDir & "\Downloads\VIPRERescue*"
;Local $sSearchDir = "C:\Temp\Downloads\VIPRERescue*"

Local $Drive = "C:\"
do
    $hVipre = FileFindFirstFile($sSearchDir)
    Do
        $Vipre = FileFindNextFile($hVipre)
        If @Error Then Exitloop
    Until StringRegExp ( $Vipre, '(?i)VIPRERescue\d+.exe', $STR_REGEXPMATCH )
Until StringRegExp ( $Vipre, '(?i)VIPRERescue\d+.exe', $STR_REGEXPMATCH )
ConsoleWrite("Moving VipreRescue" & @CRLF)
FileClose ($hVipre)
FileMove(@UserProfileDir & "\Downloads\" & $Vipre, $Drive & "PortableApps\VIPRERescuePortable\App\VIPRERescue\VIPRERescue.exe", 1)

This works for me in a test [c:\temp\..]. I think you are close to a solution for the problem.

 

This worked for me as well. Thank you very much @pluto41.

 

 

Link to comment
Share on other sites

2 minutes ago, Danyfirex said:

Hello. Just a question why InetGet does no work?

Saludos

 

Because the links I have to download the programs with are as follow:

"http://www.bleepingcomputer.com/download/farbar-recovery-scan-tool/dl/81/"
"http://www.bleepingcomputer.com/download/farbar-recovery-scan-tool/dl/82/"
"http://www.bleepingcomputer.com/download/combofix/dl/12/"
"http://www.bleepingcomputer.com/download/adwcleaner/dl/125/"
"http://go.vipreantivirus.com/?linkid=1605"
"https://www.piriform.com/ccleaner/download/portable/downloadfile"

 

I do virus removal and I always want to have the most up to date tools when I go out for a job. These links either go to a loading page or redirect to the actual download.

 

 

Link to comment
Share on other sites

I think something like this could work.

 

Local $oHttp = ObjCreate("winhttp.winhttprequest.5.1")
$oHttp.Option(6) = False
$oHttp.open("GET","http://go.vipreantivirus.com/?linkid=1605")
$oHttp.Send()
Local $sHotLink=$oHttp.GetResponseHeader("Location")
ConsoleWrite($sHotLink & @CRLF)
;~ InetGet( $sHotLink,"Somefile.temp")

Saludos

Link to comment
Share on other sites

2 minutes ago, Danyfirex said:

I think something like this could work.

 

Local $oHttp = ObjCreate("winhttp.winhttprequest.5.1")
$oHttp.Option(6) = False
$oHttp.open("GET","http://go.vipreantivirus.com/?linkid=1605")
$oHttp.Send()
Local $sHotLink=$oHttp.GetResponseHeader("Location")
ConsoleWrite($sHotLink & @CRLF)
;~ InetGet( $sHotLink,"Somefile.temp")

Saludos

 

Ah, Com Objects. Another thing I'm horrible at. Where did you learn to use these?

I have a working solution I'm happy with. I'm not going to be able to get all of those to work without spending hours working on a script. I've already dumped more time into it then I would have saved. Still, would love to know where you learned to use the $oHttp com objects. Will be useful to know in future projects.

 

 

Link to comment
Share on other sites

Link to comment
Share on other sites

6 hours ago, BetaLeaf said:
 
 

---> I know this is off topic, but: You are likely aware that Combofix has not been updated in some time, and also will not work with later operating systems? :wink:

bloopie

Edited by bloopie
fixed typo
Link to comment
Share on other sites

Last update I see (on my end) is June 2, 2015, and I believe we are still the only official download link.

Malware removal was lots of fun back in 2012 when rootkits were running rampant, and I wrote hundreds of CFScripts then...but malware is different these days (cryptolocker and the like) and CF is not updated to deal with infections out there today. Probably best to remove CF from your toolbox.

CF also makes changes to Operating System settings in its routines...some may be unwanted (like setting IE as default browser...and many others).

bloopie

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