Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How to echo a CRLF or Enter at the end of an Echo'd redirected command.

Posted on 2008-11-17
Medium Priority
Last Modified: 2012-05-05
software:  MS's FTP.exe command line.
I am dynamically creating an FTP script from a batch file, so that each time it runs it creates a folder on the FTP host with the current date time in the format "yyyy-mm-dd at hhmmss"

rem another line in the script defines the string to an env var.
dt1 = <calculated data time string - all ready works>

rem Single line of script shown below.
echo dt1 >> c:\ftp.scr

The problem is that I need to add a carrage return line feed or enter characters to the end of the line, either in the echo or as part of dt1 as other lines are appended to the script both before and after this command.  How can this be done by using only the batch file.

@echo off
:: file = MakeNewFolderCurrentDateTime.bat
:: description = this batch file uses current date and time to create a file with a unique filename
:: Date         Author    Change/Update
:: 04-Jun-2005  AGButler  Original
:: set variables
set tdtd=none
set ttrn=none
:: get the date and time and then into single variable
for /F "tokens=2-4 delims=/ " %%i in ('date /t') do set tdtd=%%i%%j%%k
for /F "tokens=2 delims=/ " %%i in ('date /t') do set mm=%%i
for /F "tokens=3 delims=/ " %%i in ('date /t') do set dd=%%i
for /F "tokens=4 delims=/ " %%i in ('date /t') do set yyyy=%%i
for /F "tokens=5-9 delims=:. " %%i in ('echo.^| time ^| find "current" ') do set ttrn=%%i%%j%%k%%l%%m
for /F "tokens=5 delims=:. " %%i in ('echo.^| time ^| find "current" ') do set h=%%i
for /F "tokens=6 delims=:. " %%i in ('echo.^| time ^| find "current" ') do set m=%%i
for /F "tokens=7 delims=:. " %%i in ('echo.^| time ^| find "current" ') do set s=%%i
for /F "tokens=9 delims=:. " %%i in ('echo.^| time ^| find "current" ') do set pm=%%i
set tufn=%tdtd% %ttrn%.txt
set date1=%yyyy%-%mm%-%dd%
set time1=%h%%m%%s%%pm%
rem type NUL>%date1% 
rem md %%date1%%
:: now create the file or Directory
set tufn=%tdtd%%ttrn%
:: Make Folder
:: md %date1%@%time1%
:: Make File
rem type NUL>%tufn%.txt
@Echo off
Echo Running Script to dynamically Create FTP Script file.
Echo Z,
Echo cr.txt is "copy con cr.txt" <enter><ctrl-m><ctrl-z>enter from command prompt.
echo ctrl-z yes to above.
echo lcd m:\FTP > c:\ftp.scr
echo open networkerweb.com >> c:\ftp.scr
echo userid >> c:\ftp.scr
echo password >> c:\ftp.scr
echo MKD %date1%@%time1% >> c:\ftp.scr
echo bye >> c:\ftp.scr
echo quit >> c:\ftp.scr
Rem Just to view the file below.
notepad c:\ftp.scr

Open in new window

Question by:rfreeman1960
  • 2
LVL 43

Expert Comment

by:Steve Knight
ID: 22976095
Not sure what you are asking for here.  If you do an echo something>>whatever.txt it will create a file with

something <cr><lf>

if ou want a blank line in a file just use

echo. >>yourfile.txt

Some of your script with time/date could be simplified using %time% and %date% along with %time:~0,2% etc. to get first two chars etc. and %time::=% to strip all colons out etc. but if its working leave as is...

If you could clarify will look again later if someone hasn't solved inbetween

LVL 16

Accepted Solution

t0t0 earned 375 total points
ID: 22980320
To create a file comprising of just the carriage return and linefeed charcters, you could copy the console to a file named CRLF such as:


Then, press the carriage return key (or ENTER key) just once only. This will place the two characters into the newly created file named CRLF.

Finally, to close the file CRLF, press CTRL-Z followed immediately by the ENTER key (at which point you'll see tha familiar "1 file(s) copied." message ).

(You'll notice the file length of CRLF is just 2 bytes - as you would expect it to be)

To use the CRLF file, in your case, suppose you want to add a CR and LF character to your file, this can be done as follows:

echo dt1>>c:\ftp.scr
copy CRLF>>c:\ftp.scr

As dragon-it pointed out above, the follwing would also work in your case:

echo dt1>>c:\ftp.scr

(notice the fullstop character after the echo statement).

On a final note.... if you have a hex file viewer, you'll notice in both instances redirecting the output into an empty file you get the follwing two characters:

0D 0A

(I use ztree for windows v1.60 for viewing files in hex mode)

Author Closing Comment

ID: 31517448
Worked great!
LVL 16

Expert Comment

ID: 24641825
Thank you for the points and for posting an interesting question.

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The way I use Experts Exchange to assist me in analyzing and diagnosing a problem is I first enter a Verbose Question at Experts Exchange like: Office 2007 will hang when opening and saving files I then launch WordPad (any text editor will do) an…
Have you ever had a hard drive that you can't boot into, but need to change the registry? Here is the solution! This article guides you through accessing and editing a registry of a non-primary drive. To read registry information on a non-prim…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question