In Windows, add a prefix to multiple PDF files











up vote
2
down vote

favorite












I have a folder with 100 invoices & they all need to carry the prefix "INVOICE_" in front. I tried to run a command but it doesn't seem to be working.

I've tried ren * INVOICE_*.PDF but it doesn't work. Can someone help me figure this out?










share|improve this question









New contributor




Lia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • softwarerecs.stackexchange.com is the preferred place to ask about apps which you could add to do this, should you be using Windows which does not know how to do that.
    – K7AAY
    Nov 15 at 0:36

















up vote
2
down vote

favorite












I have a folder with 100 invoices & they all need to carry the prefix "INVOICE_" in front. I tried to run a command but it doesn't seem to be working.

I've tried ren * INVOICE_*.PDF but it doesn't work. Can someone help me figure this out?










share|improve this question









New contributor




Lia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • softwarerecs.stackexchange.com is the preferred place to ask about apps which you could add to do this, should you be using Windows which does not know how to do that.
    – K7AAY
    Nov 15 at 0:36















up vote
2
down vote

favorite









up vote
2
down vote

favorite











I have a folder with 100 invoices & they all need to carry the prefix "INVOICE_" in front. I tried to run a command but it doesn't seem to be working.

I've tried ren * INVOICE_*.PDF but it doesn't work. Can someone help me figure this out?










share|improve this question









New contributor




Lia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have a folder with 100 invoices & they all need to carry the prefix "INVOICE_" in front. I tried to run a command but it doesn't seem to be working.

I've tried ren * INVOICE_*.PDF but it doesn't work. Can someone help me figure this out?







windows cmd.exe






share|improve this question









New contributor




Lia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Lia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 15 at 0:38









K7AAY

3,06621437




3,06621437






New contributor




Lia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 15 at 0:28









Lia

111




111




New contributor




Lia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Lia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Lia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • softwarerecs.stackexchange.com is the preferred place to ask about apps which you could add to do this, should you be using Windows which does not know how to do that.
    – K7AAY
    Nov 15 at 0:36




















  • softwarerecs.stackexchange.com is the preferred place to ask about apps which you could add to do this, should you be using Windows which does not know how to do that.
    – K7AAY
    Nov 15 at 0:36


















softwarerecs.stackexchange.com is the preferred place to ask about apps which you could add to do this, should you be using Windows which does not know how to do that.
– K7AAY
Nov 15 at 0:36






softwarerecs.stackexchange.com is the preferred place to ask about apps which you could add to do this, should you be using Windows which does not know how to do that.
– K7AAY
Nov 15 at 0:36












4 Answers
4






active

oldest

votes

















up vote
2
down vote













A quick and dirty batch file which will do what you want.



@echo off
::Create a temporary filename.
set _tmpfile=%random%

::Store the prefix you want to use in the rename in a variable
set _prefix=INVOICE_

::List of files to be renamed are held in the _tmpfile
::so be sure that you are in the correct folder/directory.
dir *.pdf /b>%_tmpfile%

::Now, loop through the _tmpfile and rename each file using the _prefix variable
:: Remove the ECHO below in order for this to work.
for /f %%x in (%_tmpfile%) do ECHO ren %%x %_prefix%%%x

::Delete the _tmpfile
if exist %_tmpfile% del %_tmpfile%


Update: the batch file, as is, won't rename the files. It would just show you the command it would run if you remove the "ECHO" string from the "for /f in %%x" line. Then the batch file will rename the files.



Hope this helps!






share|improve this answer























  • You might want to explain the bit about doing a dry run and then deleting the ECHO.  (2) Why don’t you just do for %%x in (*.pdf) do and skip the tmpfile?
    – Scott
    Nov 15 at 20:56










  • @scott: for #1, I thought the comments in the batch file would be enough. I'll update the answer. For #2, during my testing, the batch would add the prefix twice to the first file. Figured safest thing was to redirect to temp file, then loop that.
    – JSanchez
    Nov 16 at 0:44


















up vote
1
down vote













The ren command works differently than you expect; click on its link to learn more about it. A third party file renaming utility will make this much easier. There are a number of Open Source free programs which are available, such as
https://sourceforge.net/projects/renameit/
http://file-folder-ren.sourceforge.net/
https://sourceforge.net/projects/mfrv02/
https://sourceforge.net/projects/multifilerename/
https://sourceforge.net/projects/freefilerenamer/
https://sourceforge.net/projects/personalrenamer/
http://regexrenamer.sourceforge.net/
http://rename.sourceforge.net/

among others.



Can't make a recommendation of a specific app here, but https://softwarerecs.stackexchange.com is the preferred place to ask about apps.






share|improve this answer




























    up vote
    1
    down vote













    You question title says “in Windows”,
    so I’m going to ignore the cmd.exe tag
    and give you a PowerShell solution. 
    Go into PowerShell
    (type powershell at your cmd prompt, or run it from the menu)
    and type



    dir *.pdf | rename-item -newname {$_.name -replace "^","INVOICE_"}


    Seems pretty self-explanatory: take the name of each PDF file
    and rename it to a new name that’s formed
    by replacing the beginning of the old name
    (denoted by the regular expression ^) with “INVOICE_”.



    Copied almost verbatim
    from How to Batch Rename Multiple Files in Windows at How-To Geek.






    share|improve this answer




























      up vote
      -1
      down vote













      Try this command



      ren *.pdf INVOICE_*.pdf






      share|improve this answer





















        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "3"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });






        Lia is a new contributor. Be nice, and check out our Code of Conduct.










         

        draft saved


        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1375506%2fin-windows-add-a-prefix-to-multiple-pdf-files%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        2
        down vote













        A quick and dirty batch file which will do what you want.



        @echo off
        ::Create a temporary filename.
        set _tmpfile=%random%

        ::Store the prefix you want to use in the rename in a variable
        set _prefix=INVOICE_

        ::List of files to be renamed are held in the _tmpfile
        ::so be sure that you are in the correct folder/directory.
        dir *.pdf /b>%_tmpfile%

        ::Now, loop through the _tmpfile and rename each file using the _prefix variable
        :: Remove the ECHO below in order for this to work.
        for /f %%x in (%_tmpfile%) do ECHO ren %%x %_prefix%%%x

        ::Delete the _tmpfile
        if exist %_tmpfile% del %_tmpfile%


        Update: the batch file, as is, won't rename the files. It would just show you the command it would run if you remove the "ECHO" string from the "for /f in %%x" line. Then the batch file will rename the files.



        Hope this helps!






        share|improve this answer























        • You might want to explain the bit about doing a dry run and then deleting the ECHO.  (2) Why don’t you just do for %%x in (*.pdf) do and skip the tmpfile?
          – Scott
          Nov 15 at 20:56










        • @scott: for #1, I thought the comments in the batch file would be enough. I'll update the answer. For #2, during my testing, the batch would add the prefix twice to the first file. Figured safest thing was to redirect to temp file, then loop that.
          – JSanchez
          Nov 16 at 0:44















        up vote
        2
        down vote













        A quick and dirty batch file which will do what you want.



        @echo off
        ::Create a temporary filename.
        set _tmpfile=%random%

        ::Store the prefix you want to use in the rename in a variable
        set _prefix=INVOICE_

        ::List of files to be renamed are held in the _tmpfile
        ::so be sure that you are in the correct folder/directory.
        dir *.pdf /b>%_tmpfile%

        ::Now, loop through the _tmpfile and rename each file using the _prefix variable
        :: Remove the ECHO below in order for this to work.
        for /f %%x in (%_tmpfile%) do ECHO ren %%x %_prefix%%%x

        ::Delete the _tmpfile
        if exist %_tmpfile% del %_tmpfile%


        Update: the batch file, as is, won't rename the files. It would just show you the command it would run if you remove the "ECHO" string from the "for /f in %%x" line. Then the batch file will rename the files.



        Hope this helps!






        share|improve this answer























        • You might want to explain the bit about doing a dry run and then deleting the ECHO.  (2) Why don’t you just do for %%x in (*.pdf) do and skip the tmpfile?
          – Scott
          Nov 15 at 20:56










        • @scott: for #1, I thought the comments in the batch file would be enough. I'll update the answer. For #2, during my testing, the batch would add the prefix twice to the first file. Figured safest thing was to redirect to temp file, then loop that.
          – JSanchez
          Nov 16 at 0:44













        up vote
        2
        down vote










        up vote
        2
        down vote









        A quick and dirty batch file which will do what you want.



        @echo off
        ::Create a temporary filename.
        set _tmpfile=%random%

        ::Store the prefix you want to use in the rename in a variable
        set _prefix=INVOICE_

        ::List of files to be renamed are held in the _tmpfile
        ::so be sure that you are in the correct folder/directory.
        dir *.pdf /b>%_tmpfile%

        ::Now, loop through the _tmpfile and rename each file using the _prefix variable
        :: Remove the ECHO below in order for this to work.
        for /f %%x in (%_tmpfile%) do ECHO ren %%x %_prefix%%%x

        ::Delete the _tmpfile
        if exist %_tmpfile% del %_tmpfile%


        Update: the batch file, as is, won't rename the files. It would just show you the command it would run if you remove the "ECHO" string from the "for /f in %%x" line. Then the batch file will rename the files.



        Hope this helps!






        share|improve this answer














        A quick and dirty batch file which will do what you want.



        @echo off
        ::Create a temporary filename.
        set _tmpfile=%random%

        ::Store the prefix you want to use in the rename in a variable
        set _prefix=INVOICE_

        ::List of files to be renamed are held in the _tmpfile
        ::so be sure that you are in the correct folder/directory.
        dir *.pdf /b>%_tmpfile%

        ::Now, loop through the _tmpfile and rename each file using the _prefix variable
        :: Remove the ECHO below in order for this to work.
        for /f %%x in (%_tmpfile%) do ECHO ren %%x %_prefix%%%x

        ::Delete the _tmpfile
        if exist %_tmpfile% del %_tmpfile%


        Update: the batch file, as is, won't rename the files. It would just show you the command it would run if you remove the "ECHO" string from the "for /f in %%x" line. Then the batch file will rename the files.



        Hope this helps!







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 16 at 0:48

























        answered Nov 15 at 1:20









        JSanchez

        1,51289




        1,51289












        • You might want to explain the bit about doing a dry run and then deleting the ECHO.  (2) Why don’t you just do for %%x in (*.pdf) do and skip the tmpfile?
          – Scott
          Nov 15 at 20:56










        • @scott: for #1, I thought the comments in the batch file would be enough. I'll update the answer. For #2, during my testing, the batch would add the prefix twice to the first file. Figured safest thing was to redirect to temp file, then loop that.
          – JSanchez
          Nov 16 at 0:44


















        • You might want to explain the bit about doing a dry run and then deleting the ECHO.  (2) Why don’t you just do for %%x in (*.pdf) do and skip the tmpfile?
          – Scott
          Nov 15 at 20:56










        • @scott: for #1, I thought the comments in the batch file would be enough. I'll update the answer. For #2, during my testing, the batch would add the prefix twice to the first file. Figured safest thing was to redirect to temp file, then loop that.
          – JSanchez
          Nov 16 at 0:44
















        You might want to explain the bit about doing a dry run and then deleting the ECHO.  (2) Why don’t you just do for %%x in (*.pdf) do and skip the tmpfile?
        – Scott
        Nov 15 at 20:56




        You might want to explain the bit about doing a dry run and then deleting the ECHO.  (2) Why don’t you just do for %%x in (*.pdf) do and skip the tmpfile?
        – Scott
        Nov 15 at 20:56












        @scott: for #1, I thought the comments in the batch file would be enough. I'll update the answer. For #2, during my testing, the batch would add the prefix twice to the first file. Figured safest thing was to redirect to temp file, then loop that.
        – JSanchez
        Nov 16 at 0:44




        @scott: for #1, I thought the comments in the batch file would be enough. I'll update the answer. For #2, during my testing, the batch would add the prefix twice to the first file. Figured safest thing was to redirect to temp file, then loop that.
        – JSanchez
        Nov 16 at 0:44












        up vote
        1
        down vote













        The ren command works differently than you expect; click on its link to learn more about it. A third party file renaming utility will make this much easier. There are a number of Open Source free programs which are available, such as
        https://sourceforge.net/projects/renameit/
        http://file-folder-ren.sourceforge.net/
        https://sourceforge.net/projects/mfrv02/
        https://sourceforge.net/projects/multifilerename/
        https://sourceforge.net/projects/freefilerenamer/
        https://sourceforge.net/projects/personalrenamer/
        http://regexrenamer.sourceforge.net/
        http://rename.sourceforge.net/

        among others.



        Can't make a recommendation of a specific app here, but https://softwarerecs.stackexchange.com is the preferred place to ask about apps.






        share|improve this answer

























          up vote
          1
          down vote













          The ren command works differently than you expect; click on its link to learn more about it. A third party file renaming utility will make this much easier. There are a number of Open Source free programs which are available, such as
          https://sourceforge.net/projects/renameit/
          http://file-folder-ren.sourceforge.net/
          https://sourceforge.net/projects/mfrv02/
          https://sourceforge.net/projects/multifilerename/
          https://sourceforge.net/projects/freefilerenamer/
          https://sourceforge.net/projects/personalrenamer/
          http://regexrenamer.sourceforge.net/
          http://rename.sourceforge.net/

          among others.



          Can't make a recommendation of a specific app here, but https://softwarerecs.stackexchange.com is the preferred place to ask about apps.






          share|improve this answer























            up vote
            1
            down vote










            up vote
            1
            down vote









            The ren command works differently than you expect; click on its link to learn more about it. A third party file renaming utility will make this much easier. There are a number of Open Source free programs which are available, such as
            https://sourceforge.net/projects/renameit/
            http://file-folder-ren.sourceforge.net/
            https://sourceforge.net/projects/mfrv02/
            https://sourceforge.net/projects/multifilerename/
            https://sourceforge.net/projects/freefilerenamer/
            https://sourceforge.net/projects/personalrenamer/
            http://regexrenamer.sourceforge.net/
            http://rename.sourceforge.net/

            among others.



            Can't make a recommendation of a specific app here, but https://softwarerecs.stackexchange.com is the preferred place to ask about apps.






            share|improve this answer












            The ren command works differently than you expect; click on its link to learn more about it. A third party file renaming utility will make this much easier. There are a number of Open Source free programs which are available, such as
            https://sourceforge.net/projects/renameit/
            http://file-folder-ren.sourceforge.net/
            https://sourceforge.net/projects/mfrv02/
            https://sourceforge.net/projects/multifilerename/
            https://sourceforge.net/projects/freefilerenamer/
            https://sourceforge.net/projects/personalrenamer/
            http://regexrenamer.sourceforge.net/
            http://rename.sourceforge.net/

            among others.



            Can't make a recommendation of a specific app here, but https://softwarerecs.stackexchange.com is the preferred place to ask about apps.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 15 at 0:47









            K7AAY

            3,06621437




            3,06621437






















                up vote
                1
                down vote













                You question title says “in Windows”,
                so I’m going to ignore the cmd.exe tag
                and give you a PowerShell solution. 
                Go into PowerShell
                (type powershell at your cmd prompt, or run it from the menu)
                and type



                dir *.pdf | rename-item -newname {$_.name -replace "^","INVOICE_"}


                Seems pretty self-explanatory: take the name of each PDF file
                and rename it to a new name that’s formed
                by replacing the beginning of the old name
                (denoted by the regular expression ^) with “INVOICE_”.



                Copied almost verbatim
                from How to Batch Rename Multiple Files in Windows at How-To Geek.






                share|improve this answer

























                  up vote
                  1
                  down vote













                  You question title says “in Windows”,
                  so I’m going to ignore the cmd.exe tag
                  and give you a PowerShell solution. 
                  Go into PowerShell
                  (type powershell at your cmd prompt, or run it from the menu)
                  and type



                  dir *.pdf | rename-item -newname {$_.name -replace "^","INVOICE_"}


                  Seems pretty self-explanatory: take the name of each PDF file
                  and rename it to a new name that’s formed
                  by replacing the beginning of the old name
                  (denoted by the regular expression ^) with “INVOICE_”.



                  Copied almost verbatim
                  from How to Batch Rename Multiple Files in Windows at How-To Geek.






                  share|improve this answer























                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    You question title says “in Windows”,
                    so I’m going to ignore the cmd.exe tag
                    and give you a PowerShell solution. 
                    Go into PowerShell
                    (type powershell at your cmd prompt, or run it from the menu)
                    and type



                    dir *.pdf | rename-item -newname {$_.name -replace "^","INVOICE_"}


                    Seems pretty self-explanatory: take the name of each PDF file
                    and rename it to a new name that’s formed
                    by replacing the beginning of the old name
                    (denoted by the regular expression ^) with “INVOICE_”.



                    Copied almost verbatim
                    from How to Batch Rename Multiple Files in Windows at How-To Geek.






                    share|improve this answer












                    You question title says “in Windows”,
                    so I’m going to ignore the cmd.exe tag
                    and give you a PowerShell solution. 
                    Go into PowerShell
                    (type powershell at your cmd prompt, or run it from the menu)
                    and type



                    dir *.pdf | rename-item -newname {$_.name -replace "^","INVOICE_"}


                    Seems pretty self-explanatory: take the name of each PDF file
                    and rename it to a new name that’s formed
                    by replacing the beginning of the old name
                    (denoted by the regular expression ^) with “INVOICE_”.



                    Copied almost verbatim
                    from How to Batch Rename Multiple Files in Windows at How-To Geek.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 15 at 7:04









                    Scott

                    15.4k113789




                    15.4k113789






















                        up vote
                        -1
                        down vote













                        Try this command



                        ren *.pdf INVOICE_*.pdf






                        share|improve this answer

























                          up vote
                          -1
                          down vote













                          Try this command



                          ren *.pdf INVOICE_*.pdf






                          share|improve this answer























                            up vote
                            -1
                            down vote










                            up vote
                            -1
                            down vote









                            Try this command



                            ren *.pdf INVOICE_*.pdf






                            share|improve this answer












                            Try this command



                            ren *.pdf INVOICE_*.pdf







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 15 at 0:47









                            Keltari

                            48.8k17112161




                            48.8k17112161






















                                Lia is a new contributor. Be nice, and check out our Code of Conduct.










                                 

                                draft saved


                                draft discarded


















                                Lia is a new contributor. Be nice, and check out our Code of Conduct.













                                Lia is a new contributor. Be nice, and check out our Code of Conduct.












                                Lia is a new contributor. Be nice, and check out our Code of Conduct.















                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1375506%2fin-windows-add-a-prefix-to-multiple-pdf-files%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Index of /

                                Tribalistas

                                Listed building