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

rfreeman1960 used Ask the Experts™
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

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

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

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)


Worked great!

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial