locked
Can't delete a file using expandenvironmentstrings RRS feed

  • Question

  • Hi,

    I can't figure this one out....   There is a file located in %userprofile%\appdata\local\Microsoft\forms  that I want to delete.  The name is FRMCACHE.DAT.  I want to first create a text file if the text file doesn't exist - and for the script to exit if it does..

    Modifying an existing script that would copy a file from a network share I came up with the following:

    The first part (checking and creating[if need be]) works, but I cannot delete the file.

    Any advice would be much appreciated

    Adrian

    dim path
    path=CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%\AppData\Local\Microsoft\FORMS\")
    dim objFSO
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FileExists("C:\imanupgrade1.txt") = False Then
    objFSO.CreateTextFile("C:\imanupgrade1.txt")
    objFSO.DeleteFile(PATH & FRMCACHE.DAT)

    Else WScript.Quit

    End If


    anr

    Tuesday, March 1, 2016 11:50 PM

Answers

  • You need to go and read the instructions:

    objFSO.DeleteFile( path & "FRMCACHE.DAT")

    Skip  trying to learn VBScript and learn PowerShell.


    \_(ツ)_/

    • Proposed as answer by Mike Laughlin Wednesday, March 2, 2016 4:15 PM
    • Marked as answer by AdrianRoe Wednesday, March 2, 2016 4:37 PM
    Wednesday, March 2, 2016 1:12 AM

All replies

  • You need to go and read the instructions:

    objFSO.DeleteFile( path & "FRMCACHE.DAT")

    Skip  trying to learn VBScript and learn PowerShell.


    \_(ツ)_/

    • Proposed as answer by Mike Laughlin Wednesday, March 2, 2016 4:15 PM
    • Marked as answer by AdrianRoe Wednesday, March 2, 2016 4:37 PM
    Wednesday, March 2, 2016 1:12 AM
  • thank you jrv - that worked like a charm!  Knew I'd be humbled .....

    anr

    Wednesday, March 2, 2016 3:47 PM
  • Just my 2 cents, but I can't agree with jrv more on this one. You really should put all of your future effort into PowerShell. It'll save you time down the road.

    Wednesday, March 2, 2016 4:17 PM
  • hi Mike,

    I'm plowing through a "Sam's" book on powershell, but my supervisor won't let me make the necessary group policy changes -yet - to enable winRM throughout the relevant OUs.  I agree with both you and "jrv", though.

    Have a good day.


    anr

    Wednesday, March 2, 2016 4:39 PM
  • Cheers, same to you.

    As a note though - you don't need remoting enabled to delete files from other machines. You can just use the admin share.


    Wednesday, March 2, 2016 4:41 PM
  • thank you jrv - that worked like a charm!  Knew I'd be humbled .....

    anr


    The whole process is much easier in PowerShell

    \_(ツ)_/

    Wednesday, March 2, 2016 6:10 PM