回复 4# yunyan100
用set替换当前路径为空,得到相对路径的方法如下:- @echo off&setlocal ENABLEDELAYEDEXPANSION
- cd /d "%~dp0"
-
- echo %cd%
- set "currdir=%cd%"
- for /f "delims=" %%i in ('dir /b /a-d /s "*"') do (
- call :get_relative_path "%%~i"
- )
-
- type 1.txt
- pause
- goto :EOF
-
- :get_relative_path
- set "full_path=%~1"
- set rel_path=!full_path:%currdir%=!
- >>1.txt (echo "%rel_path%")
复制代码 自己读出1.txt的时候根据情况解除2边引号吧,不加引号的话,&符号echo会悲剧. |