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

Author Topic: Command prompt- altering file titles  (Read 2405 times)

0 Members and 1 Guest are viewing this topic.

AliceC

    Topic Starter


    Newbie

    Thanked: 1
    • Experience: Beginner
    • OS: Windows 8
    Command prompt- altering file titles
    « on: April 28, 2017, 10:12:52 AM »
    Hi everyone! I am brand brand new to messsing around with command prompt, though I've already accomplished a few tasks with it. I work for an office that gives us no administrative access and I can't get any additional software which makes some tasks horribly tedious. One project I have coming up involves adding the word "inactive" to the front of thousands of PDF file names, all scattered among hundreds of folders within a single master folder. I've seen sites that suggest there is a way to use command prompt to batch  prepend file names, but so far nothing I've tried has worked. Does anyone have any suggestions as to how to add to the front of all of the PDF file names stored in a master folder?

    Basically, I have files with numerical file names like "12345" and "123654" and I need to rename all of the PDF's as "inactive 123456" or "inactive 123654" so that we keep the file on record but can instantly identify it as an old form that's not to be re-used. So I have a folder on my HD "form library" that's got lots of subfolders in it. I need to be able to rename every PDF file in all of its subfolders.

    Thanks for your help!

    Alice
    « Last Edit: April 28, 2017, 11:01:19 AM by AliceC »

    Hackoo



      Intermediate
    • Thanked: 12
    • Experience: Expert
    • OS: Windows 10
    Re: Command prompt- altering file titles
    « Reply #1 on: April 28, 2017, 10:33:24 AM »
    Can you explain more your aim with an example, i mean what did you have like folder or subfolders ? and where are located all your PDF files ?
    What did you expected as output name of your PDF files and so on...
    For example if you have a PDF file named Sample.pdf ; you want to rename it as Prefix_Sample.pdf or something else ?
    Your Prefix = inactive
    so the new name becomes like that inactive_Sample.pdf ?
    « Last Edit: April 28, 2017, 10:47:24 AM by Hackoo »

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 981
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows XP
    Re: Command prompt- altering file titles
    « Reply #2 on: April 28, 2017, 10:39:20 AM »
    Here is a short batch that gives the names and paths of all PDF files.

    Code: [Select]
    DIR *.PDF /B /S >LIST.TXT
    The /B option gives a brief for of the path and file name.
    The /S option does all directories below the current.
    The LIST.TXT will have the list of all the files.




    Hackoo



      Intermediate
    • Thanked: 12
    • Experience: Expert
    • OS: Windows 10
    Re: Command prompt- altering file titles
    « Reply #3 on: April 29, 2017, 12:59:37 AM »
    Hi  :)
    Just copy and paste this code with your notepad or notepad++ and save it as Rename_PDF_Files.bat and drag and drop your master folder over it  ;)
    Code: [Select]
    @echo off
    Title Rename All PDF files in folder and its subfolders with drag and drop
    Mode con cols=75 lines=20 & color 0E
    set "Drag_Dir=%~1"
    set "Ext=pdf"
    set "Prefix=inactive"
    IF ["%Drag_Dir%"] EQU [""] Goto:Error
    2>nul cd "%Drag_Dir%" && Call :RenamePDFfiles || Goto:Error
    pause
    Explorer "%Drag_Dir%"
    Exit
    ::********************************************
    :RenamePDFfiles
    for /f "delims=" %%I in ('Dir /a-d /b /s "%Drag_Dir%\*.%Ext%" ^| findstr /I /V "%Prefix%"') do (
    Rem find all pdf's with a name does not containing the characters "inactive" and rename them.
    echo "%Prefix% %%~nxI"
        Ren "%%I" "%Prefix% %%~nxI"
    )
    Exit /b
    ::********************************************
    :Error
    Mode con cols=75 lines=5 & Color 0C
    echo(
    ECHO           You must drag and drop a folder on this batch program
    ECHO                      to rename all the PDF files
    Timeout /T 10 /NoBreak >nul
    Exit /b
    ::*****************************************