Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Adding a number to a filename  (Read 8142 times)

0 Members and 1 Guest are viewing this topic.

Shape

    Topic Starter


    Rookie

    Adding a number to a filename
    « on: February 17, 2009, 03:40:35 AM »
    Hello,

    I'm having trouble finding the right commands to rename existing files, by adding a number

    For example:
    I want to change all file names in a certain folder, by adding the nummer 7000 to the existing filename (and not change the extension of the file).

    Does anyone have any idea?

    Many thanks for your insight.

    Shape

    gpl



      Apprentice
    • Thanked: 27
      Re: Adding a number to a filename
      « Reply #1 on: February 17, 2009, 06:03:50 AM »
      How do you mean 'adding'
      from 2009-02-17.txt to 7000-2009-02-17.txt
      or
      from 2009-02-17.txt to 9009-02-17.txt

      The first is relatively simple :

      ren 2009-02-17.txt 7000-2009-02-17.txt
      The second really depends on what the file is called, as you would have to take the name, extract the part with the number, add 7000 and reinsert the result, then ren the old name to the new value


      Shape

        Topic Starter


        Rookie

        Re: Adding a number to a filename
        « Reply #2 on: February 17, 2009, 06:41:41 AM »
        The file names in the directory are different.
        For example three files are in the directory stored:
        shape.pdf
        telephone.xls
        memo.doc

        Now I want to rename these files (by command) to:
        7000shape.pdf
        7000telephone.xls
        7000memo.doc

        Referring to your answer, option two would be the right one, however, the number of files are in reality al lot more than three, and each have different names. Changing the names "manually" would take a lot of time

        I've searched for commands such as "rename" and "replace", but couldn't find the right one.
        The "rename" command for instance, doesn't add the 7000 but changes the first four tokens of the file name in 7000, if the command is: ren *.* 7000*.*

        Is this perhaps even possible in DOS commands?
        « Last Edit: February 17, 2009, 07:05:32 AM by Shape »

        BatchRocks



          Hopeful
        • Thanked: 3
          Re: Adding a number to a filename
          « Reply #3 on: February 17, 2009, 08:57:28 AM »
          Try this:

          Code: [Select]
          set /p "rena=Enter the file name and extension:
          ren %rena% 7000%rena%

          Try that.

          Shape

            Topic Starter


            Rookie

            Re: Adding a number to a filename
            « Reply #4 on: February 17, 2009, 10:18:51 AM »
            I've tried it.
            The command still changes the first four characters of the file name into 7000.

            BC_Programmer


              Mastermind
            • Typing is no substitute for thinking.
            • Thanked: 1140
              • Yes
              • Yes
              • BC-Programming.com
            • Certifications: List
            • Computer: Specs
            • Experience: Beginner
            • OS: Windows 11
            Re: Adding a number to a filename
            « Reply #5 on: February 17, 2009, 10:23:39 AM »
            It  works fine here. renamed vert.txt to 7000vert.txt.
            I was trying to dereference Null Pointers before it was cool.

            BatchRocks



              Hopeful
            • Thanked: 3
              Re: Adding a number to a filename
              « Reply #6 on: February 17, 2009, 10:27:37 AM »
              I've tried it.
              The command still changes the first four characters of the file name into 7000.

              You *SURE*? You have to be in the current directory of the files, too.

              Shape

                Topic Starter


                Rookie

                Re: Adding a number to a filename
                « Reply #7 on: February 17, 2009, 10:30:38 AM »
                A bit too quick in my answer.... ::)
                It indeed put's the 7000 in front of the file name.
                for instance:
                shape.pdf
                I fill in shape.* when prompted
                Then it renames the file with the 7000 in front of it (7000shape.pdf)

                It was however the meaning, that every file (whatever the name) should be changed.
                Getting close though!
                « Last Edit: February 17, 2009, 10:51:23 AM by Shape »

                BC_Programmer


                  Mastermind
                • Typing is no substitute for thinking.
                • Thanked: 1140
                  • Yes
                  • Yes
                  • BC-Programming.com
                • Certifications: List
                • Computer: Specs
                • Experience: Beginner
                • OS: Windows 11
                Re: Adding a number to a filename
                « Reply #8 on: February 17, 2009, 10:32:23 AM »
                what about:
                Code: [Select]
                echo add "7000" to beginning of all files in current directory?
                cd
                echo press Ctrl+Break to cancel, otherwise
                pause
                for %%P in (*.*) do ren %%P 7000%%P

                as a batch file?
                I was trying to dereference Null Pointers before it was cool.

                BatchRocks



                  Hopeful
                • Thanked: 3
                  Re: Adding a number to a filename
                  « Reply #9 on: February 17, 2009, 10:32:55 AM »
                  So...You want it to be a loop, so you enter

                  Blank.pdf
                  V
                  7000Blank.pdf

                  Then continuing

                  john.xlm
                  V
                  7000john.xlm

                  Without opening, closing, opening, closing?

                  Shape

                    Topic Starter


                    Rookie

                    Re: Adding a number to a filename
                    « Reply #10 on: February 17, 2009, 10:48:07 AM »
                    what about:
                    echo add "7000" to beginning of all files in current directory?
                    cd
                    echo press Ctrl+Break to cancel, otherwise
                    pause
                    for %%P in (*.*) do ren %%P 7000%%P
                    as a batch file?

                    THATS IT!
                    The code puts the 7000 in front of all the file names.

                    Many Thanks for you help! You have no idea, how many time this saves me ;D


                    BC_Programmer


                      Mastermind
                    • Typing is no substitute for thinking.
                    • Thanked: 1140
                      • Yes
                      • Yes
                      • BC-Programming.com
                    • Certifications: List
                    • Computer: Specs
                    • Experience: Beginner
                    • OS: Windows 11
                    Re: Adding a number to a filename
                    « Reply #11 on: February 17, 2009, 10:54:14 AM »
                    your welcome  8)

                    may it give you many saved minutes of freecell  ;D lol
                    I was trying to dereference Null Pointers before it was cool.

                    BatchRocks



                      Hopeful
                    • Thanked: 3
                      Re: Adding a number to a filename
                      « Reply #12 on: February 17, 2009, 10:54:31 AM »
                      You beat me this time D:! Good job though.