批处理文件分隔符此时出现意外

时间:2014-04-04 14:05:50

标签: batch-file

@ECHO OFF
SETLOCAL
SET "sourcedir=C:\Users\Desktop\Pipe Delimiter Project"
SET "destdir=C:\Users\Desktop\Pipe Delimiter Project"
(
 FOR /f "tokens=1-7delims=|" %%a IN ('TYPE "%sourcedir%\test.txt"') DO (
 ECHO(^|%%a^|%%b^|%%c^|%%d^|%%e^|%%f^|%%g^|
 )
)>%destdir%\newfile.txt

我收到错误:此时分隔符出乎意料......

我读到延迟扩展,不知道是否正在发挥作用,因为我没有分配变量...也读过其他类似的问题,但我不确定为什么它不读取test.txt文件...

该文件如下所示:

|abc123|1*|004|**gobbligook|001|%|2014-01-01|||||||||||||
|abc123|1*|004|**gobbligook|001|%|2014-01-01|||||||||||||
|abc123|1*|004|**gobbligook|001|%|2014-01-01|||||||||||||
|abc123|1*|004|**gobbligook|001|%|2014-01-01|||||||||||||
|abc123|1*|004|**gobbligook|001|%|2014-01-01|||||||||||||
|abc123|1*|004|**gobbligook|001|%|2014-01-01|||||||||||||
|abc123|1*|004|**gobbligook|001|%|2014-01-01|||||||||||||
|abc123|1*|004|**gobbligook|001|%|2014-01-01|||||||||||||

我希望它修剪文件的尾随管道

有人能帮助我吗?请?

1 个答案:

答案 0 :(得分:1)

您需要引用包含空格的路径:

> "%destdir%\newfile.txt"