我编写了一个文件批处理(见下文),我通过命令提示符运行,如下所示:
file K
导致
"D:\android-sd*\android-sd*-windows\*\wor*space"
我需要得到
"D:\android-sdk\android-sdk-windows\*\workspace"
否则我需要用“*”替换“android-sdk-windows”和“workspace”之间的“K”。 请问如何修复批次以获得此结果?
file.bat
@echo off
setlocal enabledelayedexpansion
set mypath="D:\android-sdk\android-sdk-windows\K\workspace"
SET mypath=!mypath:%~1=*!
echo !mypath!
提前谢谢
答案 0 :(得分:2)
@echo off
setlocal enabledelayedexpansion
set mypath="D:\android-sdk\android-sdk-windows\K\workspace"
SET mypath=!mypath:\%~1\=\*\!
echo !mypath!
答案 1 :(得分:1)
file #
:@echo off &setlocal enabledelayedexpansion
set mypath="D:\android-sdk\android-sdk-windows\#\workspace"
SET "mypath=!mypath:%~1=*!"
echo %mypath%
"D:\android-sdk\android-sdk-windows\*\workspace"
@echo off &setlocal
set "mypath=D:\android-sdk\android-sdk-windows\K\workspace"
for /f %%i in ('echo(%mypath%^|sed s/%~1/*/') do set "mypath=%%i"
echo %mypath%
"D:\android-sdk\android-sdk-windows\*\workspace"