Re: DOS Batch File Question

  • From: "Donald Marang" <donald.marang@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Thu, 1 Jul 2010 09:01:44 -0400

I would appreciate looking at your code. I started putting that exact approach together late last night and could not quite get it to work.


I also have a ugly solution using a for /f statement combined with a find statement and the ancient edlin commands. The edlin command only works with short filenames!

Don Marang

--------------------------------------------------
From: "Martin Slack" <m.g.slack@xxxxxxxxxxxx>
Sent: Thursday, July 01, 2010 2:23 AM
To: <programmingblind@xxxxxxxxxxxxx>
Subject: Re: DOS Batch File Question

Hi Don,

To do what you want in a DOS batch file, you need to use find or findstr to pull out the lines you want to remove. Those functions have an option to invert the selection so you can redirect the output, minus the chosen lines, into a temporary file. Then append the new line to that file, and finally rename it to overwrite the original file (or not) as you prefer.

I'm doing something like this myself. Let me know if you need code samples and I'll dig them out.

 Martin


----- Original Message ----- From: "Donald Marang" <donald.marang@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Thursday, July 01, 2010 4:05 AM
Subject: DOS Batch File Question


I was attempting to help someone write a batch file to help configure VMware Player to use a preconfigured Vinux Virtual Machine. We want to modify the %AppData%\VMware\preferences.ini file to set the hotkey combination to Alt + Control + Shift. To do this, I need the batch file to do two things.

1. Delete any lines that contain the word "hotkey" that are currently in the file. Two definitions are not permitted in this file. There are other similar lines that appear in this file, but only this line seems to be processed in the newest versions of the software.

2. Append a line at the bottom of the file to define the desired hotkey with the command:
echo 'pref.hotkey.shift="true"' >> %AppData%\VMware\preferences.ini

Obviously, I know how to get the second task done. Can anybody help me with the first? We would need it to work in XP, Vista and Windows 7. In Linux, I think a simple sed statement would do the trick, like
sed 'hotkey/d' ${AppData}/VMware/preferences.ini

I am just guessing at the above hypothetical syntax as well. I have not attempted anything like that in years.Does anybody know how to modify text files in DOS? I ran across 'munge', which could have accomplished this as long as an additional definitions file was used. I use the past tense since it has not been around for a long time. There must be some such capability to search and destroy! The 'FIND' command can locate the lines. I want them deleted as well.

Don Marang
__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: