Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Regular Expressions
  4. 06h36m03s to 06h36.1, etc., in filename via regex?

06h36m03s to 06h36.1, etc., in filename via regex?

Scheduled Pinned Locked Moved Regular Expressions
regexhelptutorialquestion
4 Posts 3 Posters 13 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_14835146
    wrote on last edited by
    #1

    Hello, and hoping this isn't too difficult, as I know once we get the regex, these things work beautifully. I'm not even a novice, I can never figure these complex ones out. But here's the deal. I have a capture program that captures with timestamp and a filename, which is great. Here is the format they come out as, as an example: 2022.01.30.Sun, 06h36m03s- filename 1.png 2022.01.30.Sun, 06h36m10s- filename 2.png 2022.01.30.Sun, 06h36m16s- filename 3.png 2022.01.30.Sun, 06h36m22s- filename 4.png The change that is needed is for the timestamp portion above, to be changed from this: 06h36m03s 06h36m10s to this, if under 9 files: 06h36.1 06h36.2 or to this is over 9 files: 06h36.01 06h36.02 06h36.03 06h36.04 06h36.05 06h36.06 06h36.07 06h36.08 06h36.09 06h36.10 06h36.11 So removined the seconds and just putting in a ".1" or ".01", etc., as needed. I used to just go to my renamer's forum but it's been dead quite a while now. Hoping someone here can kindly help out. Thank you in advance!

    Richard DeemingR R 2 Replies Last reply
    0
    • M Member_14835146

      Hello, and hoping this isn't too difficult, as I know once we get the regex, these things work beautifully. I'm not even a novice, I can never figure these complex ones out. But here's the deal. I have a capture program that captures with timestamp and a filename, which is great. Here is the format they come out as, as an example: 2022.01.30.Sun, 06h36m03s- filename 1.png 2022.01.30.Sun, 06h36m10s- filename 2.png 2022.01.30.Sun, 06h36m16s- filename 3.png 2022.01.30.Sun, 06h36m22s- filename 4.png The change that is needed is for the timestamp portion above, to be changed from this: 06h36m03s 06h36m10s to this, if under 9 files: 06h36.1 06h36.2 or to this is over 9 files: 06h36.01 06h36.02 06h36.03 06h36.04 06h36.05 06h36.06 06h36.07 06h36.08 06h36.09 06h36.10 06h36.11 So removined the seconds and just putting in a ".1" or ".01", etc., as needed. I used to just go to my renamer's forum but it's been dead quite a while now. Hoping someone here can kindly help out. Thank you in advance!

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      A regular expression to match the seconds is trivial: m\d+s. The problem is that a regular expression works on a single string. There is no way for a pure regex solution to group the files by the start of the name and then apply a sequential number, because the regex only sees one filename at a time, and doesn't maintain any state between invocations. If you want to do this in code, it should be fairly easy, but you'd need to specify which language you were using. If you want to use a renamer tool, you'll need to consult the documentation to see if it can do this sort of thing, and if so, how.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      M 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        A regular expression to match the seconds is trivial: m\d+s. The problem is that a regular expression works on a single string. There is no way for a pure regex solution to group the files by the start of the name and then apply a sequential number, because the regex only sees one filename at a time, and doesn't maintain any state between invocations. If you want to do this in code, it should be fairly easy, but you'd need to specify which language you were using. If you want to use a renamer tool, you'll need to consult the documentation to see if it can do this sort of thing, and if so, how.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        M Offline
        M Offline
        Member_14835146
        wrote on last edited by
        #3

        Richard, very sorry for late reply. I'm on a new browser and forgot to put in new bookmark folder for my posts! Richard, my renamer is good at handling renaming files, it's just the regex part that I dont' know how to deal with. The renamer is fantastic but in one of my crashes, I lost years worth or regex naming files all in one backup file. It was a great loss. And it handled all sorts of difficult things like this. But the renamer's forum is gone so no going back to my posts there to try to rebuild. All that's needed is the before and after, as it were. How to go from scenarios like this within the file name: 06h36m03s- filename a 06h36m05s- filename b 06h36m12s- filename c 06h36m21s- filename d 06h36m33s- filename e ... to padded from 1-9 if more than 9 i.e., if above went to 10 and beyond to: 06h36.1- filename a 06h36.2- filename b 06h36.3- filename c 06h36.4- filename d 06h36.5- filename e to padded from 1-9 if more than 9: 06h36.01- filename a 06h36.02- filename b 06h36.03- filename c 06h36.04- filename d 06h36.05- filename e 06h36.06- filename f 06h36.07- filename g 06h36.08- filename h 06h36.09- filename i 06h36.10- filename j 06h36.11- filename k I know it's a tall order but my renamer handled this type of complexity and more! I had files generated by screenshot app and recorded radio programs with all sorts of different naming conventions, and for years I used this app with perfect results. It's just that in the switch to a new computer, and all but 1 backup option, I lost of my years of scripting. Any help appreciated! Thanks!

        1 Reply Last reply
        0
        • M Member_14835146

          Hello, and hoping this isn't too difficult, as I know once we get the regex, these things work beautifully. I'm not even a novice, I can never figure these complex ones out. But here's the deal. I have a capture program that captures with timestamp and a filename, which is great. Here is the format they come out as, as an example: 2022.01.30.Sun, 06h36m03s- filename 1.png 2022.01.30.Sun, 06h36m10s- filename 2.png 2022.01.30.Sun, 06h36m16s- filename 3.png 2022.01.30.Sun, 06h36m22s- filename 4.png The change that is needed is for the timestamp portion above, to be changed from this: 06h36m03s 06h36m10s to this, if under 9 files: 06h36.1 06h36.2 or to this is over 9 files: 06h36.01 06h36.02 06h36.03 06h36.04 06h36.05 06h36.06 06h36.07 06h36.08 06h36.09 06h36.10 06h36.11 So removined the seconds and just putting in a ".1" or ".01", etc., as needed. I used to just go to my renamer's forum but it's been dead quite a while now. Hoping someone here can kindly help out. Thank you in advance!

          R Offline
          R Offline
          RedDk
          wrote on last edited by
          #4

          Personally I'm confused by what you say concerning the fabrication of "seconds" from the original set of strings returned. How do you account for the fact that sequentially, 10 (counting ten) tenths adds up to one? "Over 9 files": what the heck does that mean? In my defense I'd also like to point out that after many years of observing columns of Date Modified, Date Created, Date Accessed windows time stamps (even in MSDOS this is true), what shows is ALWAYS sortable as some "true" time. Despite two "time stamps" of the same look, underneath the msification is a millisecond disposition. Am not making any sense of this am I?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups