0

我有一个文件。包含以下值

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

(编辑 - 改进的格式)

4

1 回答 1

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
于 2013-03-13T12:42:43.090 回答