背景故事:我正在尝试通过一个批处理文件来自动化创建InternetShortcut(.url)文件的过程,该批处理文件为文本文件中的每个地址(每行一个地址)创建一个.url文件。处理两个文件:inputFile.txt和internetShortcut_creator.bat。在命令提示符下,我运行:
internetShortcut_creator.bat inputFile.txt
以下是上述两个文件的内容:
:: inputFile.txt containing one address per line
https://www.google.com/local/myfilename.pdf
https://www.wikipedia.com/dir1/dir2/dir3/slideshow.pptx
:: internetShortcut_creator.bat
SETLOCAL EnableDelayedExpansion
SET inputFile=%1
for /f "tokens=*" %%i in (%inputFile%) do (
set address=%%i
:: replace "/" with " "
set address=!address:/= !
:: attempt to extract the text after the last space, assign to %name%
for /f %%j in ("!address!") do set name=%%j
:: echo each of the extracted strings
echo !name!
)
ENDLOCAL
这里很丢人,任何帮助将不胜感激。 迈克