仅提取文件名中的数字
Extract only the numbers in file name
我只想在 .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
我需要在此代码中添加什么才能实现我的愿望?
试试这个:
echo | sed -n 's/[^0-9]//gp'
已解决!
通过使用 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!
我只想在 .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
我需要在此代码中添加什么才能实现我的愿望?
试试这个:
echo | sed -n 's/[^0-9]//gp'
已解决!
通过使用 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!