我有一个档案。包含像
这样的值E:\ABC\XYZ1\1231\AAA\SSS\name1.sql
E:\ABC\XYZ2\1232\AAA\TTT\name2.sql
E:\ABC\XYZ3\1233\AAA\UUU\name3.sql
E:\ABC\XYZ4\1234\AAA\YYY\name4.sql
E:\ABC\XYZ5\1235\AAA\ZZZ\name5.sql
我必须重新排列这些值,如
@SSS\name1.sql
@TTT\name2.sql
@UUU\name3.sql
@YYY\name4.sql
@ZZZ\name5.sql
(编辑 - 改进格式)
答案 0 :(得分:2)
尝试此操作(更改输入文件的名称):
@echo off &setlocal enabledelayedexpansion
set "fname=test.txt"
for /f "delims=" %%i in (%fname%) do (
set "fname=%%~nxi"
set "fpath=%%~dpi"
set "fpath=!fpath:~0,-1!
for %%j in (!fpath!) do set "fpath=%%~nxj"
echo @!fpath!\!fname!
)
endlocal
..如果路径结构始终相同,请使用命令行:
for /f "tokens=6,7delims=\" %i in (test.txt) do @echo @%i\%j