Find/Replace but Increment Value
Find/Replace but Increment Value
I have an .HTML file that has many photos attached to it for displaying a photo gallery. I'm replacing old photos with new ones, and I'm thinking there must be a more intelligent way than simply copying and pasting repetitive file names.
I would love to be able to replace and increment a file name on each replace, starting at a base file name of my choosing. For example...
...images/69thStreet010.jpg ...images/69thStreet011.jpg ...images/69thStreet012.jpg
Basically performing a CTRL+F and REPLACE '69thStreet010.jpg' with...
...images/xyz001.jpg ...images/xyz002.jpg ...images/xyz003.jpg
And so on until I want it to stop. Anyone here have any suggestions? Thanks a lot!
UPDATE: I should also add, I'm using Notepad++ to edit my files.
Answer by Frank Krueger for Find/Replace but Increment Value
It's time for you to learn scripting languages. Python/Ruby/Perl can do this in a few lines by using simple regular expressions and a directory listing.
Answer by Dykam for Find/Replace but Increment Value
If your S&R supports Regex, use this. Search term:
images/69thStreet([0-9]+).jpg
Replace term:
images/xyz$1.jpg
Answer by ryansstack for Find/Replace but Increment Value
There is. Create your list of photos using a python script that looks at whatever directory you want, and renames or just lists all the file names. Then go from that to a python script that generates the HTML you need (should be very easy at this point). Then copy & paste that.
Python is very easy to use, you will be able to download it in 5 minutes & find a tutorial for reading / changing file names in another 10 minutes.
Answer by Vasiliy Deych for Find/Replace but Increment Value
I just use Excel & Notepad++
Create a column of incrementing numbers in Excel. Then in the next (or previous) column, put in the line you wish to merge w/ the incrementing numbers. For instance:
file00 | 1 | .jpg file00 | 2 | .jpg
Etc.
Then copy/paste the thing into Notepad++ (or use Excel's CONCATENATE function if the job is simple) and do a replacement.
Answer by Dean Toader for Find/Replace but Increment Value
OK, I came up with a Notepad++ solution.
It does require you to install the Notepad++ plugin PythonScript. It is a TextPad-like incremental replace.
i.e.
Search and replace integer values within a string
replacing incrementally starting with 1 (0 is the default starting value):
In your case it would be
Search: ...images/69thStreet[0-9]+.jpg
Replace: ...images/xyz00\i(1).jpg
Install the PythonScript plugin.
Save the code below as a PythonScript and associate a shortcut (i.e. Ctrl+i) to it:
Then open your html file in Notepad++ and run the script below on your html file.
When prompted by the search replace dialogue, enter the following 2 lines:
...images/69thStreet[0-9]+.jpg
...images/xyz00\i(1).jpg
Now, all instances of
...images/69thStreet010.jpg
...images/69thStreet011.jpg
...images/69thStreet012.jpg
will become
...images/xyz001.jpg
...images/xyz002.jpg
...images/xyz003.jpg
Here is the PythonScript code
from Npp import * import re, string # First we'll start an undo action, then Ctrl-Z will undo the actions of the whole script editor.beginUndoAction() expression = notepad.prompt("Enter the search string on the first line, followed by Ctrl+Enter, \n" + "followed by the replace string on second line", "Incremental Search/Replace" , "") expressionList = re.split(r"[\n\r]+", expression) if len(expressionList) == 2: foundCount = [0] def incrementalReplace(parmReplaceStr,parmFoundCount): varPatternI = r'\\i\((?P[0-9]+)\)' varPatternIi = r'\\i' varPatternISearch = re.search(varPatternI , parmReplaceStr) if varPatternISearch != None: varFoundCount = int(varPatternISearch.group('starting')) + parmFoundCount[0] varReplaceString = re.sub(varPatternI ,str(varFoundCount ),parmReplaceStr) elif re.search(varPatternIi, parmReplaceStr) != None: varReplaceString = re.sub(varPatternIi,str(parmFoundCount[0]),parmReplaceStr) parmFoundCount[0] = parmFoundCount[0] + 1 return varReplaceString # Do a Python regular expression replace editor.searchAnchor() while editor.searchNext(0x00200000,expressionList[0]) != -1: editor.replaceSel(incrementalReplace(expressionList[1],foundCount)) editor.lineDown() editor.searchAnchor() # End the undo action, so Ctrl-Z will undo the above two actions editor.endUndoAction()
Answer by Dillie-O for Find/Replace but Increment Value
Look into the Column Editor feature within Notepad++. You can do a block select on the area you want to increment and then give it a starting/ending range and you're all set.
I was in a similar situation recently. I did a little bit of regular expression search/replace to get my filenames into my "default" format with some padded "000" where I wanted my incrementing to start. After that I used Shift+ALT to block select the 000s and used the editor to do the rest of the work.
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment