batch file not running

  • Thread starter Thread starter Tim Brown
  • Start date Start date
T

Tim Brown

I have written the following batch file but it does not work. If I run it
as a batch file it does not error but it does not delete the file either.

if exist "c:\documents and settings\%userprofile%\local settings\application
data\microsoft\outlook\test.txt" del "c:\documents and
settings\%userprofile%\local settings\application
data\microsoft\outlook\test.txt"

When I run it from a DOS prompt it produces this message:

The filename, directory name, or volume label syntax is incorrect.

I know that it is the %userprofile% which causes the error but is there a
way around it?

Any ideas?
 
Tim Brown said:
I have written the following batch file but it does not work. If I run it
as a batch file it does not error but it does not delete the file either.

if exist "c:\documents and settings\%userprofile%\local
settings\application
data\microsoft\outlook\test.txt" del "c:\documents and
settings\%userprofile%\local settings\application
data\microsoft\outlook\test.txt"

When I run it from a DOS prompt it produces this message:

The filename, directory name, or volume label syntax is incorrect.

dude... your question has already been answered, why are you re-posting it?

here's the answer... AGAIN!

remove 'c:\documents and settings' from the above, because the environment
variable %userprofile% already expands to 'c:\documents and
settings\username'

you can see this by typing SET at the command-line, it will show you a list
of current environment variables

thus, the batch file might look like this

@echo off
rem - deletes 'test.txt' in the outlook directory
rem - BEGIN
if exist "%userprofile%\local settings\application
data\microsoft\outlook\test.txt"
del "%userprofile%\local settings\application
data\microsoft\outlook\test.txt"
rem - END

note - the lines b/w the begin and end remarks are actually ONE line, but
wrapped for readability
 
Hi Tim,

Thank you for posting!

I totally agree with Francis' suggestion. The environment variable
%UserProfile% already contains "C:\Documents and Settings\", please remove
it from your batch file.

Have a nice day!

Thanks & Regards,

Feng Mao [MSFT], MCSE
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security

=====================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Sorry, but I could not see my message on the list so I decided to send it
again. Thanks for all your help!
 
You are welcome, Tim.

If you have any questions in the future, please don't hesitate to post in
the newsgroup.

Have a nice day!

Thanks & Regards,

Feng Mao [MSFT], MCSE
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security

=====================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top