Batch file

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?
 
G

Gordon

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?

Could it possibly be %userNAME%?
 
M

Miha Pihler

Hi Gordn,

try it like this

del "\%userprofile%\local settings\application
data\microsoft\outlook\test.txt" (without c:\...)

Mike
 
F

francis gerard

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"

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
 
A

Alex Nichol

Tim said:
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.

%userprofile% *includes* the C:\Documents and settings\ part, so just
lead the two references off as
"%userprofile%\local settings\ etc

Do a SET command to see what such environmental variables get set to
 

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

Top