Jump to content
Sign in to follow this  
triodz

Increment downloaded image filename by one

Recommended Posts

triodz

Hi Everyone! Been away from scripting for a bit and am a bit rusty. 

I was trying to get downloaded image filenames to increment by one. I was hoping to be able to check the last filename and continue from there if the program was closed and reopened again.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$biolister = GUICreate("Form1", 125, 97, 192, 124)
GUISetBkColor(0x99B4D1)
$start = GUICtrlCreateButton("Start", 8, 40, 41, 33)
GUICtrlSetBkColor(-1, 0x00FFFF)
$stop = GUICtrlCreateButton("Stop", 72, 40, 41, 33)
GUICtrlSetBkColor(-1, 0xFF0000)
$Bio = GUICtrlCreateLabel("Bio Lister", 24, 8, 80, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $filename = 0
    $sImgDir = "C:\filepathname\"&$filename&".jpg"
    $sImgUrl = "http://lorempixel.com/400/200"
    $nMsg = GUIGetMsg()
    Switch $nMsg
         Case $GUI_EVENT_CLOSE
            Exit
         Case $stop
            Exit
         case $start
            InetGet($sImgUrl, $simgdir, 1, 0)
            if fileexists( $simgdir & $filename) then $filename + 1
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites
Andreu

I personally would use an INI file in your @ScriptDir to store things such as the last filename used etc..

Use string parsing (if your file names are consistent) to obtain the last file number used... (or better yet, just store it in the ini)

So... This is an example of your INI File

[PreviousVariables]

lastNum=5

fileName=FilenameGoesHere

And this would be the code...

$oldNumber = IniRead(@ScriptDir & $INIFileName, "PreviousVariables", "lastNum", "Unfound")+1
$oldFileNam = IniRead(@ScriptDir & $INIFileName, "PreviousVariables", "fileName", "Unfound")

$NewFileName = $oldFileNam&$oldNumber

Something like that anyway... (Not tested, and free-handed under sleep deprivation... If there's a missing ", my eyes are going cross-eyed lol.

Edit:

Oh, and be sure to INIWrite to the file to update the oldNumber each time.

Edited by Andreu

Share this post


Link to post
Share on other sites
triodz

Thanks Andreu, but I can't get it to work. I do appreciate your assistance though :)

I might just do a for...next and use a batch file rename programs separately to name the files in an orderly way, being that the "for" statement will create the same names again,

Share this post


Link to post
Share on other sites
Andreu

Post an example of what you tried, and I'm sure I can fix it for you.

(Note: You do have to create an ini file... Though, using IniWrite trying to write to a ini file that doesn't exist will cause it to create it FOR you.)

Share this post


Link to post
Share on other sites
triodz

if fileexists( $simgdir & $filename) then $filename += 1

 

Sorry mate, just overwrites the file

 

Post an example of what you tried, and I'm sure I can fix it for you.

(Note: You do have to create an ini file... Though, using IniWrite trying to write to a ini file that doesn't exist will cause it to create it FOR you.)

 

It's OK, I did a for...next loop, then used a different program to rename them in chronological order. It can start renaming from the last number too, which is handy. It's heaps easier and doesn't take long.

Thanks anyways guys. Have a great night!

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  

  • Similar Content

    • Trisha
      By Trisha
      Hello,
      I Have clicked on save as option to save a file, while doing that I need to rename a file appending with sysdate. I have searched in google find the below one line of code:
      FileMove("C:\somefile.txt", "C:\somefile1.txt"), When I am trying to append with sysdate. It is not happening. Please help me out  with the small issue.
    • tintin92
      By tintin92
      Hello,

      How can I automatically download a list of zip files, like the ones in the quote, using a AutoIt script?
      Is it possible with AutoIt script?
       
    • corz
      By corz
      We've been able to drag images out of web browsers since forever. Can I drag one into my GUI?
      Or rather, can I drag an image from my web browser onto my GUI and have my app *do* something with that image?
      My fingers bleed from searching. Any ideas much appreciated!
      ;o) Cor
    • lewisg
      By lewisg
      Suddenly a RunWait command has stop working after 2 years of no errors, issues, or problems. The code uses RunWait to start Plink.exe, a command-line remote connection tool similar to UNIX ssh. I'm using it to ssh to a linux (Centos) machine, run a Perl script, and redirect the output to a file on a PC running the AutoIt script.  
       
      $FilePath = "C:\AutoIT\LED" $FilePathPlus = $FilePath & "\plink.exe" $Code1 = RunWait(@ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt ", @SW_SHOW) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " = ' & @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console The ConsoleWrite output when cut-n-pasted into a DOS box produces the expected file so I know it works. I've also tried many variations of the function moving, adding, and changing the " and ' (quote) marks. Also tried it without the @ComSpec macro and other related functions...e.g.  ShellExecuteWait , etc.
      The PC is a Windows 10 64bit and AutoIT is version 3.3.14.2.
      Searching here and Google has not yielded any clues that helped. 
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.