Search code examples
batch-filebatch-rename

Extract only the numbers in file name


I would like to only have the numbers from the file names printed in the .txt file.

C:\Users\asd123\Desktop\qwerty - 123.pdf  
C:\Users\asd123\Desktop\qw erty_456.pdf      
C:\Users\asd123\Desktop\qwe rt y789.pdf  

right now, I use:

cd C:\Users\asd123\Desktop\  
for %%a in (*.pdf) do echo %%~na >> C:\Users\asd123\Desktop\file_names.txt

what do I need to add to this code in order to have my wishes come ture?


Solution

  • SOLVED!

    By using JREPL.BAT by Dave Benham

    and STRIP.CMD :

    cd C:\Users\asd123\Desktop\
    @echo off
    echo Cleaning out old data
    :: Remove old instances of output files in order not to create duplication in the files
    del file_name_list_numerics.txt
    echo Done!
    echo Building file list.
    for %%a in (*.pdf) do echo %%~na >> C:\Users\asd123\Desktop\file_names.txt
    echo Done!
    echo Stripping non-numeric characters from file list.
    call jrepl "\D" "" /f file_names.txt /o -
    echo Done!
    echo Removing empty lines.
    For /F "delims=" %%A in (file_names.txt) Do Echo %%A >> C:\Users\asd123\Desktop\file_name_list_numerics.txt
    echo Done!
    echo Cleaning up temp data.
    del file_names.txt
    echo Done!