如何删除从多个文件空行中的目录 [英] How to delete blank lines from multiple files in a directory

查看:190
本文介绍了如何删除从多个文件空行中的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要替换从多个文件空行的目录中。我能做到这一点的一个单一的文件,但我不能够做到这一点的多个文件的文件夹中。

I need to replace blank lines from multiple files in a directory. I can do it for a single file, but I am not able to do it for multiple files in a folder.

这是code,对于单个文件的工作。

This is the code that works for a single file

@echo off
for /F "tokens=* delims=" %%A in (input.txt) do echo %%A >> output.txt

请帮我这个,因为我绝对新的批量编程

Please help me with this as I am absolutely new to batch programing

推荐答案

感谢张贴code的塔线,我一直在寻找这一点,并在一个有点着急的由我自己来推理一下:)

Thanks for posting tha line of code, I was looking for just that and in a bit of a hurry to reason it out by myself :)

要使用它的一系列文件,哟可以做到以下几点:(你可以在整个code复制到一个批处理文件)

To use it for a series of files, yo can do the following: (you can copy the whole code into a single batch file)

:: Say you have several files named Input1.txt, Input2.txt, Input3.txt, etc 
:: this will call a subroutine within the same batch file, called :Strip
:: using each file as parameter:

for %%A in ("input*.txt") do call :Strip %%A
Goto End

:Strip
:: The subroutine starts here
:: First we take the name of the input file and use it to generate
:: the name of an output file, Input1.txt would output to output_(Input1).txt, etc
For %%x in (%*) do set OutF=output_(%%~nx).txt

:: I now erase the output file it it already exists, so if you run this twice
:: it won't duplicate output
del %OutF%

:: Now comes the line you already supplied
for /F "tokens=* delims=" %%B in (%*) do echo %%B >> %OutF%

:: and now we return from the subroutine
Goto :EOF

:End

这篇关于如何删除从多个文件空行中的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆