Jump to content

Increment downloaded image filename by one


Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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,

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

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

×
×
  • Create New...