批量修改多个文件名中有空格的文件
Modify multiple files with spaces in the filenames in batch
我有一个目录 c:\test 自动填充名为 PM1 2016-10-06 1.AL1, PM1 2016-10- 的文件06 2.AL1, PM1 2016-10-07 1.AL1 等 我写了一个批处理脚本(感谢 Aacini 的核心代码!)我需要它的方式,但我的问题是它只适用于一个文件,并且该文件的文件名中不能有空格。代码:
@echo off
cd c:\test
setlocal EnableDelayedExpansion
set LF=^
%do not remove%
%these lines%
set "EOL=!LF!" & set "EOL2=!LF!"
for /f "tokens=*" %%a in (c:\test\PM1.AL1) do (
if %%a equ PROP-SUMMARY set "EOL=!LF!"
set /P "=%%a!EOL!" < NUL
set "EOL0=!EOL!" & set "EOL=!EOL2!" & set "EOL2=!EOL0!"
if %%a equ PROP-VALUES set "EOL=,"
) >>c:\test\test.tmp
TYPE c:\test\test.tmp | FIND "" /V > c:\test\PM1_new.AL1"
DEL c:\test\test.tmp
如果您对 TYPE 行感到好奇,它会将文件中的所有 CR 更改为 CRLF。
@echo off
setlocal EnableDelayedExpansion
cd c:\test
set LF=^
%do not remove%
%these lines%
for %%f in (*.*) do (
set "EOL=!LF!" & set "EOL2=!LF!"
(for /f "usebackq tokens=*" %%a in ("%%f") do (
if %%a equ PROP-SUMMARY set "EOL=!LF!"
set /P "=%%a!EOL!"
set "EOL0=!EOL!" & set "EOL=!EOL2!" & set "EOL2=!EOL0!"
if %%a equ PROP-VALUES set "EOL=,"
)) < NUL > test.tmp
TYPE test.tmp | FIND "" /V > "%%f"
)
DEL test.tmp
我有一个目录 c:\test 自动填充名为 PM1 2016-10-06 1.AL1, PM1 2016-10- 的文件06 2.AL1, PM1 2016-10-07 1.AL1 等 我写了一个批处理脚本(感谢 Aacini 的核心代码!)我需要它的方式,但我的问题是它只适用于一个文件,并且该文件的文件名中不能有空格。代码:
@echo off
cd c:\test
setlocal EnableDelayedExpansion
set LF=^
%do not remove%
%these lines%
set "EOL=!LF!" & set "EOL2=!LF!"
for /f "tokens=*" %%a in (c:\test\PM1.AL1) do (
if %%a equ PROP-SUMMARY set "EOL=!LF!"
set /P "=%%a!EOL!" < NUL
set "EOL0=!EOL!" & set "EOL=!EOL2!" & set "EOL2=!EOL0!"
if %%a equ PROP-VALUES set "EOL=,"
) >>c:\test\test.tmp
TYPE c:\test\test.tmp | FIND "" /V > c:\test\PM1_new.AL1"
DEL c:\test\test.tmp
如果您对 TYPE 行感到好奇,它会将文件中的所有 CR 更改为 CRLF。
@echo off
setlocal EnableDelayedExpansion
cd c:\test
set LF=^
%do not remove%
%these lines%
for %%f in (*.*) do (
set "EOL=!LF!" & set "EOL2=!LF!"
(for /f "usebackq tokens=*" %%a in ("%%f") do (
if %%a equ PROP-SUMMARY set "EOL=!LF!"
set /P "=%%a!EOL!"
set "EOL0=!EOL!" & set "EOL=!EOL2!" & set "EOL2=!EOL0!"
if %%a equ PROP-VALUES set "EOL=,"
)) < NUL > test.tmp
TYPE test.tmp | FIND "" /V > "%%f"
)
DEL test.tmp