How do I echo text into a specific place in a text file using a bat file?

1050 pts.
Tags:
.PST files
ECHO
Outlook
Windows Server 2003
Windows XP Pro SP3
I have a bat file CSCANPST.exe that will run automate the scanning of a pst file. This is not my creation so i cant take credit for it. I know how to return the current user, so to make this process totally automatic how do I input the username into the correct "%username%" area in the following code? One note the set PST_FILE from all my testing must all be inluded in one set of "" quotes or it will fail. ====This is the bat file to run============= REM ***This batch file will automatically run SCANPST on every PST file in the REM ***directory specified by PST_FILE_MASK. set %username% set SCANPST_PATH="C:Program FilesMicrosoft OfficeOffice12SCANPST.EXE" set PST_FILE_MASK="C:Documents and Settings" %username% & "Local SettingsApplication DataMicrosoftOutlook*.pst" REM *** CD into in the directory that contains the launched bacth file... cd %~dp0 del cscanpst.log for %%i in (%PST_FILE_MASK%) do ( REM Add an N to the end of the following line of you don't want backup files cscanpst.exe %SCANPST_PATH% "%%i" N i f errorlevel 3 goto done ) :done @echo Log: @type cscanpst.log @pause

Software/Hardware used:
xp pro sp3, office 2007,server 2003 AD

Answer Wiki

Thanks. We'll let you know when a new response is added.

I found my answer, I removed the “&” and just inserted the variable into the file.
I was thinking about VB when I was doing it.

I case anyone wants to see the fixed bat file it is below and the application I am using can be found here

http://josh.com/cscanpst/

This is a great tool and totally automates the scanpst file.

==================BAT FILE=============================
REM ***This batch file will automatically run SCANPST on every PST file in the
REM ***directory specified by PST_FILE_MASK.

set %username%
set SCANPST_PATH=”C:\Program Files\Microsoft Office\Office12\SCANPST.EXE”
set PST_FILE_MASK=”C:\Documents and Settings\%username%\Local Settings\Application Data\Microsoft\Outlook\*.pst”
pause
REM *** CD into in the directory that contains the launched bacth file…
cd %~dp0

del cscanpst.log

for %%i in (%PST_FILE_MASK%) do (

REM Add an N to the end of the following line of you don’t want backup files

cscanpst.exe %SCANPST_PATH% “%%i” N
if errorlevel 3 goto done
)
:done

@echo Log:
@type cscanpst.log

@pause

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • carlosdl
    I'm not sure I understand this part: "I know how to return the current user, so to make this process totally automatic how do I input the username into the correct "%username%" area in the following code?" Could you please provide more details ? Does this bat script work ? How does it work, and how would you want it to work ? %username% returns the current user name. Do you want to run the script for a user that is not the current one and pass the user name as a parameter ?
    69,175 pointsBadges:
    report
  • carlosdl
    Great. Didn't see your answer until I submitted my comment.
    69,175 pointsBadges:
    report
  • swinehart6803
    Sorry not being as clear as I should have been. In the process of answering this I discovered I should have put tags for scanning pst files and outlook related tags. I am going to try and have the tags updated to better reflect the question and answer.
    1,050 pointsBadges:
    report
  • Pjb0222
    I recommend using a subroutine instead of the multiline in the for loop if you should update it in the future. You may want to remove the "if ErrorLevel GOTO :DONE" inside the FOR loop processing. This will stop processing any further PST files once the error condition occurs. That is unless you entend to stop processing furhter files after the error.
    3,310 pointsBadges:
    report
  • swinehart6803
    [...] How do I echo text into a specific place in a text file using a … [...]
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following