1

I am using following vbscript but it seems not working to copy file. If I use absolute file path it works.

How to set these path in windows 7 to work.

Const DestinationFile = "%UserProfile%\Desktop\plrplus.dotm"
Const SourceFile = "%UserProfile%\Desktop\PLRPlus\plrplus.dotm"

Set fso = CreateObject("Scripting.FileSystemObject")
    'Check to see if the file already exists in the destination folder
    If fso.FileExists(DestinationFile) Then
        'Check to see if the file is read-only
        If Not fso.GetFile(DestinationFile).Attributes And 1 Then 
            'The file exists and is not read-only.  Safe to replace the file.
            fso.CopyFile SourceFile, "%UserProfile%\Desktop\plrplus.dotm" True
        Else 
            'The file exists and is read-only.
            'Remove the read-only attribute
            fso.GetFile(DestinationFile).Attributes = fso.GetFile(DestinationFile).Attributes - 1
            'Replace the file
            fso.CopyFile SourceFile, "%UserProfile%\Desktop\plrplus.dotm", True
            'Reapply the read-only attribute
            fso.GetFile(DestinationFile).Attributes = fso.GetFile(DestinationFile).Attributes + 1
        End If
    Else
        'The file does not exist in the destination folder.  Safe to copy file to this folder.
        fso.CopyFile SourceFile, "%UserProfile%\Desktop\plrplus.dotm", True
    End If
Set fso = Nothing

1 Answers1

0

from suggestion of DavidPostill, this two different things worked.

Desktop is special folder so for it:

Set objShell = CreateObject( "WScript.Shell" )    
objShell.SpecialFolders("Desktop")

For other folders in the users we can expand the environment strings

Set objShell = CreateObject( "WScript.Shell" )    
objShell.ExpandEnvironmentStrings("%APPDATA%")
  • So did your final statement look like: fso.CopyFile SourceFile, objShell.SpecialFolders("Desktop"), True – AxGryndr Jul 14 '16 at 16:14