Jump to content

Strange problem with variable %userprofile%


kukris

Recommended Posts

The following commands won't work

dir %userprofile%\recent\*.*
del %userprofile%\recent\*.*

The following error is displayed

The system cannot find the path specified.

However when I use

cd %userprofile%\recent

it changes to my profile folder and in the subfolder recent where I can use the DEL command

My profile doesn't contain any special characters, just a dot in the profile name.

Has someone a solution for this?

Link to comment
Share on other sites


Use quotes:

dir "%userprofile%\recent"

del "%userprofile%\recent\*.*"

%userprofile% contains spaces ("C:\Documents and Settings\username"), so you need to delimit the path with quotes for dir & del to work.

Link to comment
Share on other sites

Here is a VBS script that will delete all the files in Recent

Save As DeleteRecent.Vbs

Dim Act	: Set Act = CreateObject("Wscript.shell")
Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
Dim User : User = Act.ExpandEnvironmentStrings("%userProfile%\recent\")
Dim Folder : Set Folder = Fso.GetFolder(User)
Dim Files : Set Files = Folder.Files
Dim objFile
For Each objFile in Files
Fso.DeleteFile(objFile.Path), True
Next
Act.Popup "Completed Script",5,"Finished",0 + 32 + 0

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...