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. Rename File Name Help

Rename File Name Help

Scheduled Pinned Locked Moved Regular Expressions
helptutorial
4 Posts 2 Posters 17 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.
  • T Offline
    T Offline
    toikken
    wrote on last edited by
    #1

    Hi, I have file lectures and I would like to change the nameing convention. Currently, it has the format of {detail -} subject - author.wmv I would like to rename with the nameing convention of author - subject { - detail}.wmv Some observation, initialy, the author is at the end of the file name preceded by a seperator of minus sign. {detail -} is optional and thus some file name utilize. Thus, we can have more than one minus sign as seperator but author name is always at end of file name preceded by the minus sign seperator. Example file names; e4 e5 - The Four Kn1ghts for Black - Vig0rito.wmv e4 e5 The Sc0tch for Black - Part 1 - Vig0rito.wmv 2+1=2; A Practical Endgam3 Example from L1nares - P@schall.wmv Result ( I would like. That is, lecturer seperator topic ) Vig0rito - e4 e5 - The Four Kn1ghts for Black.wmv Vig0rito - e4 e5 The Sc0tch for Black - Part 1.wmv P@schall - 2+1=2; A Practical Endgam3 Example from L1nares.wmv Purpose, I would like to access material by author. Thank in advance for your help.

    B 1 Reply Last reply
    0
    • T toikken

      Hi, I have file lectures and I would like to change the nameing convention. Currently, it has the format of {detail -} subject - author.wmv I would like to rename with the nameing convention of author - subject { - detail}.wmv Some observation, initialy, the author is at the end of the file name preceded by a seperator of minus sign. {detail -} is optional and thus some file name utilize. Thus, we can have more than one minus sign as seperator but author name is always at end of file name preceded by the minus sign seperator. Example file names; e4 e5 - The Four Kn1ghts for Black - Vig0rito.wmv e4 e5 The Sc0tch for Black - Part 1 - Vig0rito.wmv 2+1=2; A Practical Endgam3 Example from L1nares - P@schall.wmv Result ( I would like. That is, lecturer seperator topic ) Vig0rito - e4 e5 - The Four Kn1ghts for Black.wmv Vig0rito - e4 e5 The Sc0tch for Black - Part 1.wmv P@schall - 2+1=2; A Practical Endgam3 Example from L1nares.wmv Purpose, I would like to access material by author. Thank in advance for your help.

      B Offline
      B Offline
      Bernhard Hiller
      wrote on last edited by
      #2

      You can use System.IO.Path.GetFileNameWithoutExtension(). Then find the position of the last "-" with the LastIndexOf('-') function of the string class. Build up your new string from the respective Substring()s.

      T 1 Reply Last reply
      0
      • B Bernhard Hiller

        You can use System.IO.Path.GetFileNameWithoutExtension(). Then find the position of the last "-" with the LastIndexOf('-') function of the string class. Build up your new string from the respective Substring()s.

        T Offline
        T Offline
        toikken
        wrote on last edited by
        #3

        Thank you for your reply Bernhard and introduction to system io. Currently, I am using a free file renaming tool that utilize regexp. After looking at the coding and re-familiarizing myself with regexp and having no luck, I made a post. The next morning, I came with a quasi-solution. I do not want to spam the tool but it is the most complex rfr*k according to review. What unique about this file title renaming is the number of seperators can vary. Thus, mp3 titles with challenging non-fix number of seperators would find this thread informative. I am stump trying to access the last seperator with $ anchor to create an expression and thus sent this sos. Here is my quasi-solution and hope it helps some with similar problem. (?x)(.*?)[ ]*?[-]+[ ]*?(.*) [ ]*?[-]+[ ]*?(.*) # start of swap 2 fields \3 zzzz \2 zzzz \1

        # Handle Linaries example
        _ (?x)(.*?)[ ]*?[_]+[ ]*?(.*)$ # Linaries example \2 zzzz \1 \bzzzz\b # Convert back to minus sign - (.?)\bwmv\b # remove the .wmv after the author name to null I use zzzz and _ as temporary strings with the understanding that they are unique in my files. Adapt accordingly. I adapted from a swap 2 fields expression. The five lines and replace work for my demo example. Thanks. Edit: Some minor quirks but liveable. tx

        B 1 Reply Last reply
        0
        • T toikken

          Thank you for your reply Bernhard and introduction to system io. Currently, I am using a free file renaming tool that utilize regexp. After looking at the coding and re-familiarizing myself with regexp and having no luck, I made a post. The next morning, I came with a quasi-solution. I do not want to spam the tool but it is the most complex rfr*k according to review. What unique about this file title renaming is the number of seperators can vary. Thus, mp3 titles with challenging non-fix number of seperators would find this thread informative. I am stump trying to access the last seperator with $ anchor to create an expression and thus sent this sos. Here is my quasi-solution and hope it helps some with similar problem. (?x)(.*?)[ ]*?[-]+[ ]*?(.*) [ ]*?[-]+[ ]*?(.*) # start of swap 2 fields \3 zzzz \2 zzzz \1

          # Handle Linaries example
          _ (?x)(.*?)[ ]*?[_]+[ ]*?(.*)$ # Linaries example \2 zzzz \1 \bzzzz\b # Convert back to minus sign - (.?)\bwmv\b # remove the .wmv after the author name to null I use zzzz and _ as temporary strings with the understanding that they are unique in my files. Adapt accordingly. I adapted from a swap 2 fields expression. The five lines and replace work for my demo example. Thanks. Edit: Some minor quirks but liveable. tx

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4

          OK, that's different background. In that case, I'd rely on the "greedy" character of wild cards. (?<part1>.*)\s-\s(?<part2>.*)(?<ext>\.wmv) will catch the parts and the extension, and the re-order it to become part2 - part1.ext

          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