Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

batch file

Jan 31, 2007 4:05PM PST

Hi.

I'm new to batch files, and have delved rather deep (for me anyway)

I have created a batch file that so far.
Will connect to remote DOS console, and execute a deletion of a set .txt file.
it first identifies the size of the file, and then asked if you wish to delete it.

advisory notes are to delete the file if over 5mb.

if user selects no, then batch closed with message not deleted.
if user selects yes, then batch file will delete the said file.
after this I then need it to alter a .ini file to read AppendToLog=0 (originally set to value 1)

I don't know of any way to do this other than sending the file to the c drive then copying the file to the DIR to overwrite the original.


I can only connect to the remote computer DOS prompt by an existing .exe file.

batch looks a little like.


=====================
@echo off

rem %1 = remote machine name/ip
rem %2 = users logon id
rem /r:1 = is switch built into remote dos command exe

brcmd \\%1 /r:1 "dir c:\docume~1\%2\applic~1\micros~1\intern~1\brndlog.txt"

echo Delete file if over 5,000,000 bytes.

choice Delete file
***unsure of rest of choice command ***
***cant remember - I don't really ***
***understand it - explanation would ***
***be good! ***
if not %errorlevel% neq 2 goto choiceno

:choiceyes

brcmd \\%1 /r:1 "del c:\docume~1\%2\applic~1\micros~1\intern~1\brndlog.txt" "xcopy \\rbkegcmpfs02\slss\hda\servic~1\brutil~1\brndlog.ini c:\docume~1\%2\applic~1\micros~1\intern~1\"

rem \\rbkegcmpfs02 = file server
*** this returns "access denied" as user I'm executing command from doesn't have network admin rights that I do***
:choiceno
echo you selected not to deleting file

:end
echo on

=================
So I need preferably to be able to edit the file through a batch file.

==============================
breakdown of things i need help with.
1.)
explanation as to how the CHOICE command works, and an example (i have it working but I don't understand how it does.)
2.)
how can I edit a file through a batch?
ie edit file called brndlog.ini which contents reads "AppendToLog=1"
to make it read "AppendToLog=0"
3.)
Any other ideas?

Discussion is locked

- Collapse -
Re: batchfile
Feb 1, 2007 6:15PM PST

1. Choice

http://furies.senecac.on.ca/~cpang/ios100/bat_help.htm#choice gives the help for choice
http://www.techiwarehouse.com/cms/engine.php?page_id=9f59e25f gives some explanation
http://www.techiwarehouse.com/cms/engine.php?page_id=8dc6cfa1 gives an example

2. Editing
It's difficult or impossible to do the editing in batch. Why not use a workaround? Replace the file with an empty file (one of 0 bytes) and let the program append to that. That really is quite the same as having it create a new one. If this isn't what you need, please explain the problem in stead of asking for an impossible solution.

Kees

- Collapse -
More about editing.
Feb 1, 2007 10:08PM PST
http://www.grymoire.com/Unix/Sed.html

Now before you reply it's for UNIX be sure to find it for DOS/Windows.

The problem with your batch file program is that the batch file "language" doesn't do a few things you have asked it to do. For instance you may have to find a program to report the size of the file greater than or less than some parameter.

Can I be Frank? Frank sez "Use another language."

Bob
- Collapse -
Another language?
Feb 4, 2007 6:18AM PST

I've completed the batch file and it's fully working.

The batch file is to stop IE logging, and to remove the current logs, which often takes a users profile over size limit.

I elected to copy the file across to the remote machine, which was already set correctly.

On reporting that size of the file, I simply used this command
brcmd \\%1 /r:1 "dir c:\docume~1\%2\applic~1\micros~1\intern~1\brndlog.txt"

Not a clear cut as I would have liked, but does the job.

- Collapse -
multiple sounds
Feb 7, 2007 7:55AM PST

path="G:\";%path%
one.wav
pause
path="G:\";%path%
two.mp3

is there any way to pause x seconds without having to click a button.