Avatar of IntercareSupport
IntercareSupport
 asked on

Insert carraige return at the end of multiple files?

I have a directory of 770 text files.  I need to insert a carraige return at the end of each file.  What's the best way to do this?  Batch file, powershell, perl-I don't care the coding style.  Thanks!
PowershellMicrosoft DOSPerl

Avatar of undefined
Last Comment
Ben Personick (Previously QCubed)

8/22/2022 - Mon
Steve Knight

OK make sure you have a backup then try this:

@echo off
cd /d "C:\yourdir"
for /f "delims=" %%a in ('dir /b *.txt') do echo. >>"%%~a"

This should append a blank line (which is what echo. does) using >> to append to the end of each file it finds using the dir command.

Like I said try on a test file or two first!

Steve
ASKER CERTIFIED SOLUTION
Steve Knight

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
IntercareSupport

ASKER
Perfect!  Thanks!
Ben Personick (Previously QCubed)

@Steve, I think your idea of setting delims=" will still use the default of space and quote, not sure..

 Also, I'm pretty sure that Windows CMD won't have this issue anymore, but I recall having issues where it would echo the command into the file if it was not told to mute echos of the command..

Also I noticed you accidentally left the Batch double % in the command on the A, which needs to be fixed.

@Author,

If you have any issues with the above try this:

At the Command Line of the computer where the files are:
@FOR /F "Tokens=*" %F ('DIR /B "Drive-Letter:\Path To\Text Files\*.txt" A:-D') DO @ECHO.>>"%~F"

Open in new window


At a Remote Command Line
@FOR /F "Tokens=*" %F ('DIR /B "\\ServerName\Share\Path To\Text Files\*.txt" A:-D') DO @ECHO.>>"%~F"

Open in new window



In a Batch File for Local Directory:
@ECHO OFF

SET "FullFilePath=Drive-Letter:\Location\Of Folder\With Files"

FOR /F "Tokens=*" %%F ('DIR /B "%FullFilePath%\*.txt" A:-D') DO ECHO.>>"%%~F"

Pause

Open in new window



In a Batch File for Remote File Location:
@ECHO OFF
SET "Server=ServerName or IP"
SET "FilePath=Share\Location\Of Folder\With Files"

FOR /F "Tokens=*" %%F ('DIR /B "\\%Server%\%FilePath%\*.txt" A:-D') DO ECHO.>>"%%~F"
Pause

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Steve Knight

Glad it helped... sorry for typos, was being jumped on at the time (young boys....)
Ben Personick (Previously QCubed)

lol, yeah, just missed the close of the posting too, couldn't have expected more than assist anyway.

  Steve you always write good code, boys or no you answered it quickly and well.

-Q