仅提取文件名中的数字

时间:2018-01-24 13:30:31

标签: batch-file batch-rename

我想只在.txt文件中打印文件名中的数字。

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

现在,我用:

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

为了让我的愿望成真,我需要为此代码添加什么?

2 个答案:

答案 0 :(得分:0)

试试这个:

echo | sed -n 's/[^0-9]//gp'

答案 1 :(得分:0)

已解决!

使用Dave Benham的 JREPL.BAT

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!