Find/Replace but Increment Value

后端 未结 7 697
庸人自扰
庸人自扰 2020-12-31 18:35

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 inte

相关标签:
7条回答
  • 2020-12-31 19:02

    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.

    0 讨论(0)
  • 2020-12-31 19:03

    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.

    0 讨论(0)
  • 2020-12-31 19:12

    notepad++ allows you to make multi line editing. But the main problem here is to get as quick as possible all the file names from the directory where they are.

    In the past I had similar challenge that I solved this way. This works almost on all win vers.

    To make a list of all files in a directory create a bat file into the dir itself.

    copy and paste there the following batch code

    dir /b > filelist.txt
    

    Save the file with name

    makefilelist.bat
    

    Not important the name you give it: the important thing is the file extension .bat

    Double click on the bat file just saved: the batch script executes a clean dir command inside the directory in witch it is executed redirecting the output to the file filelist.txt

    In less than one sec you have the output saved into the filelist.txt witch will be similar to the following:

    filelist.txt
    Image File Name 01.gif
    Image File Name 02.gif
    Image File Name 03.gif
    Image File Name 04.gif
    Image File Name 05.gif
    Image File Name 06.gif
    Image File Name 07.gif
    Image File Name 08.gif
    Image File Name 09.gif
    Image File Name 10.gif
    Image File Name 11.gif
    Image File Name 12.gif
    Image File Name 13.gif
    Image File Name 14.gif
    Image File Name 15.gif
    Image File Name 16.gif
    Image File Name 17.jpg
    Image File Name 18.jpg
    Image File Name 19.jpg
    Image File Name 20.jpg
    Image File Name 21.jpg
    Image File Name 22.jpg
    Image File Name 23.jpg
    Image File Name 24.jpg
    Image File Name 25.jpg
    Image File Name 26.jpg
    Image File Name 27.jpg
    Image File Name 28.jpg
    Image File Name 29.jpg
    Image File Name 30.jpg
    Image File Name 31.jpg
    Image File Name 32.jpg
    Image File Name 33.PNG
    Image File Name 34.PNG
    Image File Name 35.PNG
    Image File Name 36.PNG
    Image File Name 37.PNG
    Image File Name 38.PNG
    Image File Name 39.PNG
    Image File Name 40.PNG
    Image File Name 41.PNG
    Image File Name 42.PNG
    Image File Name 43.PNG
    Image File Name 44.PNG
    Image File Name 45.PNG
    Image File Name 46.PNG
    Image File Name 47.PNG
    Image File Name 48.PNG
    makelist.bat
    

    Of course the names logged into the file list may vary... The script logs every file, no matters if it is in sequence or not or if its name is a random name or contains date time (time stamp) etc.: it logs everything is into the same dir in witch is executed...

    Now you can open filelist.txt with notepad++: first delete the lines of the list that report the unwanted files:

    makelist.bat

    filelist.txt

    This operation is necessary cause the script lists also itself and the filelist.txt.

    Then with multi line editing tool add the tag around all lines at once, or everything else needed to built the photo gallery, even a javascript array, etc... in the end copy and paste the finished job to your image gallery file under coding. Done. Easy as drinking a glass of water: it is more difficult to explain than to do! Granted. ;-)


    Improvements:

    It is possible to get a list of just the jpg files by modifying the batch command like the following:

    dir *.jpg /b > filelist.txt
    
    Image File Name 17.jpg
    Image File Name 18.jpg
    Image File Name 19.jpg
    Image File Name 20.jpg
    Image File Name 21.jpg
    Image File Name 22.jpg
    Image File Name 23.jpg
    Image File Name 24.jpg
    Image File Name 25.jpg
    Image File Name 26.jpg
    Image File Name 27.jpg
    Image File Name 28.jpg
    Image File Name 29.jpg
    Image File Name 30.jpg
    Image File Name 31.jpg
    Image File Name 32.jpg
    

    The same with other file extensions.

    0 讨论(0)
  • 2020-12-31 19:15

    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.

    0 讨论(0)
  • 2020-12-31 19:20

    If your S&R supports Regex, use this. Search term:

    images/69thStreet([0-9]+).jpg
    

    Replace term:

    images/xyz$1.jpg
    
    0 讨论(0)
  • 2020-12-31 19:21

    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.

    0 讨论(0)
提交回复
热议问题