dos batch file

Microsoft Running ms-dos 20th anniversar...
February 15, 2010 at 04:50:52
Specs: Windows XP
HI,
I have a request that I need to do the following.I have a file for example in c:\test directory - I need a batch file that will open the c:\test file, and append one line of text to the end of the file, and close it. Then I need to be able to transfer this file to another server, once its transferred - I need to rename the file, move it to a backup folder...and then creat a log file with time stamp....
Any help would be greatly appreciated
thanks

See More: dos batch file

Report •


#1
February 15, 2010 at 05:48:24
Not tested.

--------------------------
@echo off & setLocal EnableDELAYedeXpansion

>> filename echo my new bottom line
copy filename s:\incoming
move s:\incoming\filename s:\backup\newname
> mylog echo filename moved to s:\backup\newname at %TIME%


=====================================
Helping others achieve escape felicity

M2


Report •

#2
February 15, 2010 at 07:04:04
thanks a million, going to try it out and see if it gives me the start that I need.

Report •

#3
February 15, 2010 at 07:44:57
Tried the following..
@ echo off & setLocal EnableDELAYedeXpansion
set version_str=$header benelux_ftp.bat 0.1 2010/02/15 $
set descr="Benelux FTP File Transfers"
set filename=d:\ccl_interface\benelux_test_ccl\data\first.txt
set bottom_line=this is last line
echo %bottom_line%
echo %filename%
>>filename echo bottom_line
rem copy filename d:\incoming
rem move s:\imcoming\filename s:\backup\newname

works as far as the echo - but not loading the bottom line into the file - is there something I'm doing wrong? thanks


Report •

Related Solutions

#4
February 15, 2010 at 08:18:33
To use vars you need to address them as vars.

>>%filename% echo %bottom_line%


=====================================
Helping others achieve escape felicity

M2


Report •

#5
February 16, 2010 at 04:32:57
Brilliant - thank you.It did write to a local file, but when I try to write to the one defined in %filename% its giving invalid directory unable to create. I've checked, and put in cd d:\ to try it there and then tried cd d:\ccl_interface\ but its giving me invalid directory even when I go no further than changing the directory a level. Is this something that you might have seen before?
thanks

Report •

#6
February 16, 2010 at 04:52:11
I'm going out the door but I'll get back to you.

Note that to change directory *AND* DRIVE you need:

cd /d d:\zzz

OR:

pushd d:\zzz


=====================================
Helping others achieve escape felicity

M2


Report •

#7
February 16, 2010 at 04:55:52
you are so good...its so long since i did any of this stuff, am finding it a nightmare...is there any book u would recommend for all this - am used to typing it at dos prompt but not in batch files...

Report •

#8
February 16, 2010 at 05:01:26
tried both suggestions no luck - am not even changing drives, just want to change directories...
so for example if you were in d:\hello\world
and you want to change to d:\hello\me
tried using cd d:\hello\me
then tried using cd d:\hello
then tried pushd d:\hello
and still no luck....giving me invalid directory

Report •

#9
February 16, 2010 at 05:09:22
Get to d:\hello and do a TREE to see if you have the directories that you think you have.

And beware of spaces, especially trailing ons. To check, use Windows Explorer and browse to the directory in question. Press F@ [rename] to see if there are any chars which are not obvious.


=====================================
Helping others achieve escape felicity

M2


Report •

#10
February 16, 2010 at 06:47:14
yep, tried all that...no luck - even recreated the directories....

Report •

#11
February 16, 2010 at 06:59:17
Not underatanding this...

"tried both suggestions no luck - am not even changing drives, just want to change directories..."

did you do a...

cd\hello\me

in the c:\hello\world directory??? That should change the directory. It could be long directory names in which case you need quotes around your command like in the following...

c:\hello\world\> "cd\hello world\"
c:\hello world\>

Because the directory name is longer than 8 characters and has special characters like spaces then you need quotes around your command. This is also assuming the directory exists.

P.S. Can you post the code you have so far so we can help you achieve your original goal?

If it helps her is a backup script I have for my users using ROBOCOPY as my backup tool but you could use XCOPY if you feel like it...

@echo off
@taskkill /im outlook.exe
Set Monthfolder=Monthly\%Date:~-4,4%-%Date:~-10,2%

Cls
@echo Backing up local files...

if not exist \\10.100.100.7\backups\userfiles\%username% goto createdir 
goto end

:createdir
md \\10.100.100.7\backups\userfiles\%username%
goto end

:end
@\\10.100.100.7\scripts\robocopy "%userprofile%" \\10.100.100.7\backups\userfiles\%username%\Daily *.do* /if *.xl* /if *.pdf /if *.pp* /if *.txt /XD %userprofile%\AppData /XD "%userprofile%\local settings" /XD "%userprofile%\Application Data" /s /COPY:DAT /r:1 /w:1 /np /xo /eta >> h:\BackupLog.txt
echo Backing up Email...
ver | find "Version 5." > nul
if %ERRORLEVEL% == 0 \\10.100.100.7\scripts\robocopy "%userprofile%" \\10.100.100.7\backups\userfiles\%username%\%monthfolder% *.pst* /s /COPY:DAT /r:1 /w:1 /np /xo /eta >> h:\BackupLog.txt

Note the "ver | find "Version 5." > nul
if %ERRORLEVEL% == 0" is for the Windows Vista and 7 computers because of their different directory structure.


Report •

#12
February 16, 2010 at 07:37:53
below is what i'm entering....
basically it wont allow me to change directories...
have tried inverted commas, push d, etc...
checked directory names for strange characters etc..but no luck
basically trying to write to a text file in another directory, one text line
after that then I have to transfer the file, rename it, and move to another directory - not going to worry about that bit yet though
any help would be great


@ echo off & setLocal EnableDELAYedeXpansion
set version_str=$header benelux_ftp.bat 0.1 2010/02/15 $
set descr="Benelux FTP File Transfers"
set filename=d:\ccl_interface\benelux_payroll_ccl\data\first.txt
set directory=d:\ccl_interface\benelux_payroll_ccl\data
set bottom_line=this is last line
echo %bottom_line%
echo %filename%
dir
pushd \ccl_interface\benelux_payroll_ccl\data
"cd d:\ccl_interface\benelux_payroll_ccl\data"
dir
>>%filename% echo %bottom_line%
rem copy filename d:\incoming
rem move s:\imcoming\filename s:\backup\newname


Report •

#13
February 17, 2010 at 04:06:03
I don't know how a fairly simple thing can get this convoluted.

You did this SET:

set directory=d:\ccl_interface\benelux_payroll_ccl\data

but didn't use it.

-----------------------------------------------
This line:

pushd \ccl_interface\benelux_payroll_ccl\data

will only work if you are on the drive with that path.
Impossible to know.
-----------------------------------------------------
This line:

"cd d:\ccl_interface\benelux_payroll_ccl\data"

won't work in any case.
-------------------------------------------------
You probably need: [I'm guessing]

pushd d:\ccl_interface\benelux_payroll_ccl\data


=====================================
Helping others achieve escape felicity

M2


Report •

#14
February 17, 2010 at 07:00:30
Like said above try this...

@ echo off & setLocal EnableDELAYedeXpansion

set version_str=$header benelux_ftp.bat 0.1 2010/02/15 $
set descr="Benelux FTP File Transfers"
set filename=first.txt
set directory=d:\ccl_interface\benelux_payroll_ccl\data
set bottom_line=this is last line
set newfilename=%Date:~-7,2%-%Date:~-10,2%-%Date:~-4,4%.txt
rem I added this to do the current date as mentioned.

echo %bottom_line%
echo %filename%

dir
rem not sure why you are doing this.

pushd "%directory%"
rem Note you do not need this if you do the next command as such...

dir "%directory%" >> "%directory%\%filename%" 
echo %bottom_line%

copy "%directory%\%filename%" d:\incoming
move "s:\imcoming\%filename%" "s:\backup\%newname%"
rem note you should not use mapped drives. They may not always be there or be the same. Consider UNC pathing like...
rem move \\yourservername\imcoming\%filename% \\yourservername\backup\%newname%


Report •

#15
February 17, 2010 at 07:11:24
Thanks a million for your help.
Had been trying the mapping, but was getting errors, so went back to just using the normal c:\ d:\ etc...but once got it running was going back to the mapping. Turns out I was using a step routine to step through my batch file, and this was limiting the directory name lengths!! Found that out at 1am this morning! so, am back now trying to get the rest working, so so far, so good.

Thanks so much for all your help again


Report •

#16
February 17, 2010 at 07:16:01
Yes that is why I stuck quotes around every thing. The quotes tell the system to use long file names (ones longer than 8 characters) and special characters such as spaces. Do not for get them. I have gotten burned many times on the same issue.

Report •


Ask Question