Pick latest file

Hints, tips and tricks for newbies

Moderators: JRL, Dorian (MJT support)

Post Reply
Check
Newbie
Posts: 2
Joined: Tue Jul 10, 2012 11:44 am

Pick latest file

Post by Check » Wed Aug 07, 2013 4:02 pm

Hi everyone,

this one is giving me troubles: I have two, three or four files named pic_day_hour_second.jpg, now I need a way to rename them in the order of creation, the oldest would be pic_1.jpg, the next pic_2.jpg.

Thanks for any hint.

User avatar
JRL
Automation Wizard
Posts: 3529
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Aug 08, 2013 1:50 pm

Something like this?

Code: Select all

//Set this folder name appropriately.
Let>FileLocation=c:\filerenametest

Let>RP_Wait=1
Let>RP_Windowmode=0
RunProgram>cmd /c dir %FileLocation%\*.jpg /od /b > %temp_dir%filerenametemptextfile
Wait>0.1
ReadFile>%temp_dir%filerenametemptextfile,vData
DeleteFile>%temp_dir%filerenametemptextfile

Separate>vData,crlf,vLine

Let>kk=0
Repeat>kk
  Add>kk,1
  Let>value=vLine_%kk%
  RenameFile>%FileLocation%\%value%,%FileLocation%\pic_%kk%.jpg
Until>kk={%vLine_Count%-1}

MDL>Complete

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts