如何将文件名解析为用连字符分隔的两部分?
我希望它输出到一个包含以下内容的 txt 文件中:
Artist: Name of Artist
Song: Title of Song
使用以下批处理文件作为起点:
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2 delims=-" %%i in ('dir /b name*') do (
echo Artist: %%i
echo Song: %%j
)>>file.txt
endlocal
示例用法:
> dir name*
Volume in drive F is Expansion
Volume Serial Number is 3656-BB63
Directory of F:\test
03/06/2018 14:06 0 Name of Artist - Title of Song.mp3
03/06/2018 14:07 0 Name of Artist 1 - Title of Song 1.mp3
2 File(s) 0 bytes
0 Dir(s) 1,269,011,574,784 bytes free
> test
> type file.txt
Artist: Name of Artist
Song: Title of Song.mp3
Artist: Name of Artist 1
Song: Title of Song 1.mp3
>
我希望它为每个 mp3 文件提供一个文本文件。这可能吗?
是 使用以下批处理文件:
@echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in ('dir /b name*.mp3') do (
set _filename=%%~dpna.txt
for /f "tokens=1,2 delims=-" %%i in ("%%a") do (
echo Artist: %%i
echo Song: %%j
)>!_filename!
)
endlocal
示例用法:
> dir *.mp3
Volume in drive F is Expansion
Volume Serial Number is 3656-BB63
Directory of F:\test
03/06/2018 14:06 0 Name of Artist - Title of Song.mp3
03/06/2018 14:07 0 Name of Artist 1 - Title of Song 1.mp3
2 File(s) 0 bytes
0 Dir(s) 1,269,022,654,464 bytes free
> test
> type name*.txt
Name of Artist - Title of Song.txt
Artist: Name of Artist 1
Song: Title of Song 1.mp3
Name of Artist 1 - Title of Song 1.txt
Artist: Name of Artist 1
Song: Title of Song 1.mp3