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

Posted on 2008-11-17
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 >> 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
    LVL 43

    Expert Comment

    by:Steve Knight
    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

    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

    Worked great!
    LVL 16

    Expert Comment

    Thank you for the points and for posting an interesting question.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    This article describes how to set permissions to allow a limited-permissions user to start and stop a particular System Service.   It is always best to give users only the permissions that they need to perform their job, so tweaking particular permi…
    The password reset disk is often mentioned as the best solution to deal with the lost Windows password problem. In Windows 2008, 7, Vista and XP, a password reset disk can be easily created. But besides Windows 7/Vista/XP, Windows Server 2008 and ot…
    This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now