[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

How do you append an existing text file from a batch file?

Asked by naebeth in MS DOS, Windows Batch Scripting

Tags: DOS, batch file, CMD, TXT, text file

I have recently asked how to set a value from the registry to a variable in a batch file for a current project I'm playing with purely to further my coding/programming knowledge, and I've hit another snag.
The batch file is basically going to be executed via an AUTORUN.INF file on a CD and, when run, install a Playstation emulator (completely legal providing those who use it own a Playstation and only use it for games they own). I'll paste in my code so far below to help you understand where I'm up to and where I want to go next, followed by an extract of the INI file about to be detailed.

The emulator has an INI file in the root directory which contains, in particular, the location of several storage folders. This is handy as it allows users to have non-default locations to suit their needs. My batch file installs all necessary files and directories to a hidden folder on the system drive (as shown in the code) except the "cdimages" folder which, using a registry key value saved to a temporary variable, is installed in the users My Documents (WinXP) or equivalent folder.
Seeing as my batch file allows for users having their My Documents folder in a non-default location the batch file needs to dynamically write the absolute patch to the cdimages folder to the INI file. Which is where my problem lies. I've seen plenty of websites telling me how to dump info to a new text file or to read data from one, but I can't find anywhere detailing how to append information to a set point in an existing file.
Note: I will also be using the solution for the "screenshots" folder.
If this is not possible then fair enough, but I felt this site would probably be my best bet if a solution does exist.

Brief description of the code thus far:
Lines 3 through 8 set variables and copy a free utility onto the host machine to allow the CMD to create a shortcut file (which I haven't coded yet).
9 through 16 create the necessary folders on the host machine.
17 through 24 copy the program's files to the newly created folders.
Line 32 is the path in question.

To be added:
A section which defines the output of my %docs% variable to the cdimages location of the INI.
The creation of the shortcut file using the CMD application, shortcut.exe.

I think I've explained the situation pretty well, but I wouldn't be surprised if I've missed something or forgotten to explain things.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
REM this is the batch script up until the pause command.
@echo off
set dir=%cd%
set rootkey=HKEY_CURRENT_USER
set subkey=Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
set valuename=personal
for /f "tokens=1-2*" %%a in ('reg query "%rootkey%\%subkey%" /v %valuename% ^| find "REG_SZ"') do set docs=%%c
copy "%dir%\utils\shortcut.exe" "%windir%\system32"
mkdir "C:\PSx"
attrib +h "C:\PSx"
mkdir "C:\PSx\cards"
mkdir "C:\PSx\bios"
mkdir "C:\PSx\saves"
mkdir "C:\PSz\utils"
mkdir "%docs%\PSx\cdimages"
mkdir "%docs%\PSx\screenshots"
copy "%dir%\cards\*.bin" "C:\PSx\cards"
copy "%dir%\bios\*.bin" "C:\PSx\bios"
copy "%dir%\psxfin.exe" "C:\PSx"
copy "%dir%\psx.ini" "C:\PSx"
copy "%dir%\readme.txt" "C:\PSx"
copy "%dir%\unicows.dll" "C:\PSx"
copy "%dir%\unicows_license.txt" "C:\PSx"
copy "%dir%\utils\cdztool.exe" "C:\PSx\utils"
echo  
echo Installation complete.
pause
REM from here onwards is the extract of the INI, including the piece in question.
[Paths]
SaveStatePath="C:\PSx\saves"
MemoryCardPath="C:\PSx\cards"
CDImagePath=
ScreenShotsPath=
[BIOS]
PS1="C:\PSx\bios\SCPH1001.BIN"
PS2="C:\PSx\bios\scph39001.bin"
[+][-]08/23/09 05:02 PM, ID: 25164849Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/23/09 05:13 PM, ID: 25164881Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/23/09 05:39 PM, ID: 25164957Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/23/09 06:57 PM, ID: 25165216Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/23/09 07:02 PM, ID: 25165230Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/23/09 07:12 PM, ID: 25165262Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/23/09 07:15 PM, ID: 25165267Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: MS DOS, Windows Batch Scripting
Tags: DOS, batch file, CMD, TXT, text file
Sign Up Now!
Solution Provided By: t0t0
Participating Experts: 3
Solution Grade: A
 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625