-1

I wrote a little script which is reading out a textfile that is located in a netlogon folder. In this file their are some paths in like C:\Users\%USERNAME%\AppData\Roaming\Folder\.

My script is reading the textfile and have to delete this folder. The Problem I think is that the script doesn't know how to handle %username%. If i write C:\Users\myusername\AppData\Roaming\Folder\ in the textfile it seems to work.

How can I solve this problem?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Mustangz
  • 1
  • 3

1 Answers1

1

Use this:

Dim folderPAth, objShell, objFso
Set objShell = CreateObject("wscript.shell")
folderPath = objShell.ExpandEnvironmentStrings("C:\Users\%USERNAME%\AppData\Roaming\Folder")
Set objShell = Nothing

'To Delete the Folder
Set objFso = createObject("Scripting.FileSystemobject")
If objFso.FolderExists(folderPath) then
   objFso.DeleteFolder folderPath,True
End If
Set objFso = Nothing 

The method 'ExpandEnvironmentStrings' will replace %USERNAME% with the actual username. Now you will be able to delete the folder.

Gurmanjot Singh
  • 10,224
  • 2
  • 19
  • 43