terrypin Posted November 5, 2014 Report Share Posted November 5, 2014 I'm probably making heavy weather of this... I'm working with filenames like FrankSinatra06.jpg, always with two numbers before the extension. I want to change that to FrankSinatra07.jpg, Similarly I'd change EltonJohn09.bmp to EltonJohn10.bmp and so on, increasing the number by one. So my macro must extract those two as text, convert them to integers, add 1, and convert that back to text, finally re-assembling the new filename as FrankSinatra07.jpg Except that 07 text converts to 7 as an integer. I've been trying in vain to find a command that will pad out the integer 7 to 07. Is there one I've missed? Or must I resort to replacing a space in the resulting text by '0' to achieve this? And only at that position, as there could also be spaces in the main name. Seems messy for such a relatively trivial bit of fomatting. --Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
Cory Posted November 5, 2014 Report Share Posted November 5, 2014 I've never found one. Whenever I do something like this it's pad and replace. Maybe you should consider make a feature request to ISS asking them to add the ability to specify the padding character. Quote Link to comment Share on other sites More sharing options...
Cory Posted November 5, 2014 Report Share Posted November 5, 2014 Oh and you should treat them as separate text variables and concatenate. The name and the number that is. Take the first variable representing the file name and copy the last two digits to a new variable and then delete the last two digits form the original. Increment, pad, replace, then add the new one to the original string in the rename command. Quote Link to comment Share on other sites More sharing options...
terrypin Posted November 5, 2014 Author Report Share Posted November 5, 2014 Thanks Cory, that was quick! OK, that's what I went ahead and did meanwhile, but looks like that's the only way. It was only 3 extra commands to add the necessary If Variable, but it just seems so crude. I've emailed Insight with a feature request. --Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
terrypin Posted November 6, 2014 Author Report Share Posted November 6, 2014 I had this prompt reply from Insight: Thanks for the suggestion. Integer values are defined as whole numbers and do not contain leading zeros. So I don't think we can make that change. You will need to continue converting it back to text and adding the 0 back. So I've just added this as a Code Snippet for future use. I called it 'Pad an integer', If Variable %nNumberNew% Is Less Than "10" Variable Modify String: Replace "%tNumberNew%" in %tNumberNew% with "0%tNumberNew%" // Adds a 0End If --Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
Samrae Posted November 6, 2014 Report Share Posted November 6, 2014 Here is another way: Variable Modify String %tNumberNew%: Pad Left (2) // Pad to two characters Variable Modify String: Replace " " in %tNumberNew% with "0" Quote Link to comment Share on other sites More sharing options...
Samrae Posted November 6, 2014 Report Share Posted November 6, 2014 It is possible to add leading 0's to a number in a string variable. It is not possible to add leading 0's to a value in an integer variable. Quote Link to comment Share on other sites More sharing options...
terrypin Posted November 6, 2014 Author Report Share Posted November 6, 2014 Thanks, that's a bit tidier than mine. Terry, UK Quote Link to comment Share on other sites More sharing options...
Cory Posted November 7, 2014 Report Share Posted November 7, 2014 I thought that's what you were doing Terry. Pad and replace. Samrae's example is how I do it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.