String 在循环后/循环中从svn repo路径批量提取最后一个文件夹名
我在批处理文件中有以下部分:String 在循环后/循环中从svn repo路径批量提取最后一个文件夹名,string,batch-file,slice,String,Batch File,Slice,我在批处理文件中有以下部分: setlocal enabledelayedexpansion for /f "tokens=*" %%a in (requirements.txt) do ( set package_path=%%a set test_dir_name=!package_path:~4!/tests for %%f in ("!package_path:\= !") do set package_name=%%f echo !test_dir_name! if
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (requirements.txt) do (
set package_path=%%a
set test_dir_name=!package_path:~4!/tests
for %%f in ("!package_path:\= !") do set package_name=%%f
echo !test_dir_name!
if /i "!test_dir_name:~0,5!"=="https" (
echo ##### Testing !test_dir_name!\n
call svn export --force !test_dir_name! tests/!package_name!
)
)
cp unittest.cfg tests
cp .coveragerc tests
nose2 --plugin nose2.plugins.junitxml -s tests -c unittest.cfg
python -m coverage xml
@echo J | del /f tests
endlocal
在requirements.txt
中,我得到了如下svn存储库:
svn+https:\mysvnserver\svn\tags\1.1.0\Python\my_package
我只想从该字符串中获取我的包。
这就是我在上面第5行中尝试做的,尝试解决方案,如中所述
但这只会分割路径并返回“svn+https:mysvnserver svn-tags 1.1.0 Python my_包”
如何仅从字符串中获取我的\u包
?@ECHO OFF
SETLOCAL
设置“targetdir=svn+https:\mysvnserver\svn\tags\1.1.0\Python\my\u包”
对于/f“delims=“%%v IN”(“%targetdir%”)DO(
回声%%v
回声%%~nxv
)
后藤:EOF
这将为您提供解决问题所需的所有工具。您给定链接上接受的答案不包含任何报价:
对于(!package\u path:\=!)中的%%f,请设置package\u name=%f