//flex table opened by JP

Click to See Complete Forum and Search --> : DOS help! Batch file creation


zzzreyes@yahoo.com
02-09-2000, 09:34 PM
Well I was working on my mothers computer, and decided to install a single file game, the game is a .exe program and it has the size of about 20 megs.
The point is that she lives 6 hours from here, and she has no space left.
I am thinking of making a batch file and sending it down by email, so the file will go and delete the game.
the game is in
c:\mydocuments\deathstar.exe
how do I go about doing this?????

Thanks this is the actual batch file I did...
well I went out to the net and actually looked for more info... I did:
edit fle.bat
echo off
(#there was a problem becuase it was a whole folder and not jsut the file so I had to find a recursive method 2 delete everything without prompt!)
echo y | del c:\mydocs\folder\*.*


and that is it..
I wish dos had a unix command like rm -r
this would simplify my problem..
the pipe works fine!



[This message has been edited by zzzreyes@yahoo.com (edited 02-10-2000).]

OuTpaTienT
02-09-2000, 10:51 PM
just make a batch file with this command in it:

del c:\mydocuments\deathstar.exe


bet you didn't think it was so easy huh? http://www.sysopt.com/forum/wink.gif

[This message has been edited by OuTpaTienT (edited 02-09-2000).]

bdog
02-09-2000, 11:19 PM
I am interested in this. Like writing scripts and stuff. I do it under unix all the time and write scripts to rename or move files and then execute them by using sh command. Is there anything similar to this in windows?

Target
02-09-2000, 11:47 PM
Bdog....yes you can do so in windows as well.

Renaming a file is REN
Moving a file is MOVE
To execute it, simply type in the exe name.

To see the switches and syntax required for REN and MOVE, open a DOS window, and type for instance REN /? or MOVE /?

That will show you the proper syntax to use for each command and available switches.

*For example*
To rename a file:
REN c:\test.exe testing.exe

To move a file:
MOVE c:\testing.exe c:\mydocs\testing.exe

To run the file:
testing.exe

So, the entire example batch file using all the ones you mentioned is this:

REN c:\test.exe testing.exe
MOVE c:\testing.exe c:\mydocs\testing.exe
testing.exe

You can use any text editor you like to write the command, and then save it as *.bat

The .bat extension stands for batch file http://www.sysopt.com/forum/smile.gif


There are probably a ton of other ways to do this, but this one is pretty straight forward and fairly easy to write.

OuTpaTienT
02-10-2000, 08:56 AM
Example of a complex batch file:
__________________________________________

ECHO OFF
:intro
cls

:question
ECHO This program will update your Windows 98 Virtual Device Drivers.
ECHO.
CHOICE /C:YN This software is provided as is, without warranty of any kind. Do you wish to continue?
if errorlevel 2 goto sure
if errorlevel 1 goto cd

:sure
ECHO.
CHOICE /C:YN Are you SURE you want to quit without updating your files?
if errorlevel 2 goto intro
if errorlevel 1 goto check

:cd
ECHO.
ECHO Please insert your Windows 98 CD into your CD-ROM drive.
pause
goto scan

:scan
ECHO.
ECHO VXD_FIX.DAT will now check your system to see if you need the VXD update.
if exist %winbootdir%\system\vflatd.vxd goto no
ECHO.
ECHO.
CHOICE If you have your Windows 98 CD in the drive, press Y. If your computer came without a Windows 98 CD, press N. /C:yn
if errorlevel 2 goto oem
if errorlevel 1 goto drive

:drive
CHOICE What letter is your CD-ROM drive? /C http://www.sysopt.com/forum/biggrin.gifEFGHIJKLMNOPQRSTUVWXYZ
if errorlevel 1 set driveletter=d
if errorlevel 2 set driveletter=e
if errorlevel 3 set driveletter=f
if errorlevel 4 set driveletter=g
if errorlevel 5 set driveletter=h
if errorlevel 6 set driveletter=i
if errorlevel 7 set driveletter=j
if errorlevel 8 set driveletter=k
if errorlevel 9 set driveletter=l
if errorlevel 10 set driveletter=m
if errorlevel 11 set driveletter=n
if errorlevel 12 set driveletter=o
if errorlevel 13 set driveletter=p
if errorlevel 14 set driveletter=q
if errorlevel 15 set driveletter=r
if errorlevel 16 set driveletter=s
if errorlevel 17 set driveletter=t
if errorlevel 18 set driveletter=u
if errorlevel 19 set driveletter=v
if errorlevel 20 set driveletter=w
if errorlevel 21 set driveletter=x
if errorlevel 22 set driveletter=y
if errorlevel 23 set driveletter=z
goto extract

:extract
extract /y /a /l %winbootdir%\system %driveletter%:\win98\win98\win98_22.cab configmg.vxd
extract /y /a /l %winbootdir%\system %driveletter%:\win98\win98\win98_22.cab vcomm.vxd vdmad.vxd vdd.vxd vmouse.vxd ntkern.vxd vflatd.vxd
extract /y /a /l %winbootdir%\system\vmm32 %driveletter%:\win98\win98\win98_22.cab configmg.vxd
extract /y /a /l %winbootdir%\system\vmm32 %driveletter%:\win98\win98\win98_22.cab vcomm.vxd vdmad.vxd vdd.vxd vmouse.vxd ntkern.vxd vflatd.vxd
goto confirm

http://www.sysopt.com/forum/redface.gifem
ECHO.
ECHO VXD_FIX will now scan your hard drive for the necessary files.
pause
if not exist %winbootdir%\options\cabs\win98_22.cab goto sorry
extract /y /a /l %winbootdir%\system %winbootdir%\options\cabs\win98_22.cab configmg.vxd
extract /y /a /l %winbootdir%\system %winbootdir%\options\cabs\win98_22.cab vcomm.vxd vdmad.vxd vdd.vxd vmouse.vxd ntkern.vxd vflatd.vxd
extract /y /a /l %winbootdir%\system\vmm32 %winbootdir%\options\cabs\win98_22.cab configmg.vxd
extract /y /a /l %winbootdir%\system\vmm32 %winbootdir%\options\cabs\win98_22.cab vcomm.vxd vdmad.vxd vdd.vxd vmouse.vxd ntkern.vxd vflatd.vxd
goto confirm

:confirm
ECHO.
ECHO VXD_FIX will now verify the .VXD files have been installed succesfully.
pause
if exist %winbootdir%\system\vflatd.vxd goto congrats
if not exist %winbootdir%\system\vflatd.vxd goto error

:error
cls
ECHO.
ECHO The files were not found, please re-run VXD_FIX.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
pause
goto intro

:congrats
ECHO.
ECHO Congratulations! You have succesfully installed the VXD patch.
ECHO.
ECHO.
pause
goto end

:check
if not exist %winbootdir%\system\vflatd.vxd goto warn

:warn
ECHO.
ECHO Your System has NOT been updated, and may continue to have problems!
ECHO.
ECHO Please Re-run VXD_FIX to insure your systems stability!
pause
goto end

:no
ECHO.
ECHO.
ECHO Your System appears to not need this update.
ECHO.
ECHO.
ECHO This program will not run on a system not needing this update.
pause
goto end

:sorry
cls
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO Sorry but VXD_FIX was unable to locate the necessary cab files.
ECHO.
ECHO Please contact your PC vendor for the location of the Windows 98 cab files.
goto warn

:end
cls

ECHO Please return to Windows and re-start your computer.


[This message has been edited by OuTpaTienT (edited 02-10-2000).]

bdog
02-10-2000, 09:13 AM
Thanks for the info. I think I understand how to write them now. One question though, Target you said to execute the batch file simply type in the exe name, but you said it saves the text file as a bat file. How do I get form bat to exe?

Dave_H
02-10-2000, 09:25 AM
Target
Thanks for the explaining that and the examples you gave. I have been fooling around have have been able to re-name and move around a test document I made.
I know it might seem pretty basic to some people, but I have never known anything about these "batch files" but it gave me quite a thrill to these simple tasks in this manner.
It will give me something to play around with on this rainy day.
Thank-You http://www.sysopt.com/forum/smile.gif http://www.sysopt.com/forum/smile.gif http://www.sysopt.com/forum/smile.gif
Dave

edit- bdog, I did the batch file in "notepad"
and saved it to my desktop, then had to change the extension from .txt to .bat
double clicking on it made it execute. -edit

[This message has been edited by Dave_H (edited 02-10-2000).]

Target
02-10-2000, 09:32 AM
Sorry for the confusion Bdog. I meant that to execute a file from within a batch file (in the example I used an *exe) you simply type its name.

Once you have saved the batch file (*.bat), then you can execute the batch file from a DOS prompt, or from the start>run menu, simply by referring to the batch file name.

For instance, if its a batch file on your C:\ drive called "test" you want to start, at the DOS prompt you just type its name and the batch file will launch.
ex: C:>test.bat

From windows, its start>run>c:\test.bat

Hope this helps.

BTW, I just saw your update. Notepad is a good one to use for creating batch files, but virtually any editor or program that can create text files will do. When you go to save the file, in the file name, specify it as *.bat, rather than just putting in a file name, that way, you won't have to rename it from a *.txt file to a *.bat file.

[This message has been edited by Target (edited 02-10-2000).]

Dave_H
02-10-2000, 09:45 AM
Man, your too much http://www.sysopt.com/forum/smile.gif
I'm really learning now!
Kind of like having a new toy. http://www.sysopt.com/forum/smile.gif
Dave

OuTpaTienT
02-10-2000, 10:00 AM
Remember that batch files can come in handy in the Windows enviorment too. For example, I know of no other way to start multiple programs with a single icon. The following batch file would start Notepad, Explorer, & Solitaire:
-----------------------------------
C:\Windows\Notepad.exe
C:\Windows\explorer.exe
C:\Windows\sol.exe
-----------------------------------
Then after you save the *.bat file, right-click and goto properties and check the box "close on exit". This will insure the underlying DOS window automatically closes after the batch file is run.

OuTpaTienT
02-10-2000, 10:15 AM
zzzreyes@yahoo.com, I didn't even notice that you came back to the thread. Really should reply to thread instead of editing your original message.

Anyways, you CAN do that in DOS. If I'm understanding you correctly, you just wanted to delete the entire directory without a yes/no prompt. Right? This would do it:

-----------------------------
deltree /y c:\mydocs\folder
-----------------------------

bdog
02-10-2000, 10:34 AM
Thanks for the clarification. I understand now. Is there anything like vi for windows? It would take forever to do the things I want in notepad.

Dave_H
02-10-2000, 10:42 AM
Scary thought just came to me.
Would an anti-virus program stop such a command like that if a batch file was sent as an attachment in an e-mail?
Dave

zzzreyes@yahoo.com
02-10-2000, 10:45 AM
Sorry outpatient....(new-e here)

anyhow, I will try it that way.
I knew that deltree did something like that but did not know the deliminator.
Thanks.
How do you create a batch that will actually add a line to the autoexec.bat.
like the installation programs?

BTW: DAve- no u can't stop it. unless u recognize it, or unless your virus checker is set not 2 recieve exe files, not sure if that is possible.

Banti
02-10-2000, 10:46 AM
what I like to do is create new commands for windows. I use Unix at work, and I often type in ls at home (win). My solution...

ls.bat
-------------------------
dir /p %1
-------------------------

except for the arguements (which I could code for, but choose not to) it works!!

You can also do this with other commands...

rm.bat
---------------------------
del %1
---------------------------

These bat files need to be placed in the c:\windows\command directory


Banti

bdunn
02-10-2000, 11:27 AM
just watch out using pipes in batch files. I discovered something strange once when I was trying to setup autoexec.bat I put a rem in front of a line containing a pipe and it would stop when it reached that line.

OuTpaTienT
02-10-2000, 11:32 AM
zzzreyes. About adding a line to autoexec, there is probably a better way to do this but here is one way that seems to work. (this is what's fun about batch files, just make 'em up as you go. http://www.sysopt.com/forum/smile.gif) Here's the simple test I just did to see if this idea works:

1.bat - this is the file I want to modify (ie autoexec.bat)
2.txt - this contains the data I want to add to 1.bat

to combine those two I used this batch file:

-------------------------------------------
copy 1.bat+2.txt 3.bat
ren 1.bat 1.old
ren 3.bat 1.bat
-------------------------------------------

first line adds the text to the file and saves it as 3.bat
second line backs up 1.bat as 1.old
third line renames the new file (3.bat) to the original name, 1.bat

OuTpaTienT
02-10-2000, 11:41 AM
Here's a decent list of usable DOS commands

http://www.easydos.com/dosindex.html

nachtgeist
02-10-2000, 01:06 PM
Okay, batchfile gurus...

I have a backup program that copies essential system files to a directory. I'd like to write a batchfile that copies these backed-up files to a directory with the name being the current date, e.g. 021000.

I know how to do everything except pass the date to a variable and create the directory with that name. Halp!

Adam

zzzreyes@yahoo.com
02-10-2000, 01:19 PM
I have a backup program that copies essential system files to a directory. I'd like to write a batchfile that copies these backed-up files to a directory with the name being the current date, e.g. 021000.

NOt taht I am an expert at all...
but try expanding the time function...
for example (unix) not tested in dos altough dat is a dos command!
u could just change the name of the dir....


ren c:\$PATH\dirName $DATE

OuTpaTienT
02-10-2000, 04:38 PM
nachtgeist, wow, took some research and it's a very tricky way of doing it, but this seems to be the only way to do such a thing in DOS. All we need to do is set an enviorment variable to the current date, THEN you can use the command %enviroment variable% to call the value of that variable. To see all your current enviorment variables just type SET in DOS.

Anyways, to set a variable named DATE with the value of todays date, use this batch file:
-------------------------------------------
@ECHO OFF
REM --- sets enviorment variable DATE to current date ---
VER | date > TEMP.BAT
ECHO SET DATE=%%4 > current.BAT
CALL TEMP.BAT
DEL current.BAT
DEL TEMP.BAT
--------------------------------------------

After that you can do something like this to make a directory with the date as it's name:

md c:\backup\%date%

Pretty neat huh? If you understand how that batch files is working, then you're a helluv lot smart than I. It took me forever to figure that out. If it's still a little baffling, then here a clue that should give it away: This very similar batch file will set the variable DAY to the current day:
--------------------------------------------
@ECHO OFF
REM --- sets enviorment variable DAY to current day ---
VER | date > TEMP.BAT
ECHO SET DAY=%%3 > current.BAT
CALL TEMP.BAT
DEL current.BAT
DEL TEMP.BAT
--------------------------------------------
Now you use %day% in commands as well.

Get it?

OuTpaTienT
02-10-2000, 07:31 PM
Hey nachtgeist, you're another one! Why no email address? What's up with that?

I don't think people should be allow to sign up for the board without a valid email address. grrrrr.

zzzreyes@yahoo.com
02-11-2000, 12:57 AM
it is funny how Dos is so much like unix...
funmy, maybe because dos is a 100% rip off from unix!!!!!!
anyhow, your idea, or method is one that I would use in unix.
I would of never tought of it, but then again, I wouldn't compare my skill level to dat of an OUTPATIENT!

nachtgeist
02-11-2000, 07:46 AM
Sorry about the lack of e-mail addy; I didn't want spammers harvesting my e-mail address from here (get too much as it is). Thanks for the info... if I only knew what some of those lines do. The batchfile works, though I'll be buggered if I know exactly how... why do you have VER | DATE output instead of just ECHO | DATE ?

Man, I need some serious batchfile lessons. http://www.sysopt.com/forum/smile.gif

Adam

OuTpaTienT
02-11-2000, 01:40 PM
hehe, don't feel bad, it took me at least an hour, maybe two to figure out what this batch file was doing. I couldn't believe it was working and I didn't know how. ??

I gotta run out the door right now, check back later tonight, I come back and explain how it works. http://www.sysopt.com/forum/wink.gif

nachtgeist
02-12-2000, 09:35 AM
It woiks! Woo-hoo! Outpatient, you're my hero. Thanks a million! Now, where did you learn all that batchfile magic?


Adam

OuTpaTienT
02-12-2000, 04:20 PM
Where'd I learn it? Oh here & there. I dunno.

You wanna know how that batch file works? Here:

1.) @ECHO OFF
2.) REM --- sets enviorment variable DATE to current date ---
3.) VER | date > TEMP.BAT
4.) ECHO SET DATE=%%4 > current.BAT
5.) CALL TEMP.BAT
6.) DEL current.BAT
7.) DEL TEMP.BAT
___________________________

1.) This line just stops all the **** from displaying to your screen

2.) This is just a REMark line, does nothing

3.) This writes the output of the DATE command to the file TEMP.BAT, the VER just stops it from verifing (pausing) for input.

4.) This line writes the file CURRENT.BAT with the contents: SET DATE=%4

5.) Now the trickery. This file runs the TEMP.BAT file. That files attemps to run what was just the output of the DATE command. The first word it runs into is CURRENT, which in turn runs the CURRENT.BAT. The CURRENT.BAT (SET DATE=%4) is going to use the 4th word, from CURRENT, as it's input. The 4th word is the date (CURRENT DATE-1 IS-2 SAT-3 2-12-2000-4). Pretty nifty huh?

6.) Just clean-up, deletes the used batch files

7.) Ditto

nachtgeist
02-14-2000, 11:17 AM
Wow, that is sneaky! My question is, how did you tell it to take the 4th word in the file - was that the %4? (And I assume there are two % signs used because the first is a sort of 'escape character'?) I've used %1 when writing small batchfiles, like n.bat (which is just "notepad %1")...


Adam

OuTpaTienT
02-14-2000, 07:17 PM
yes exactly. For example if you wanted to have two inputs two on the same line you could just use %1 %2 etc. I never realized until just recently that the number actually designates which word it takes as an input.