1

I'm writing a script to move an Outlook signature into %APPDATA%\Microsoft\Signatures\ and it's just not going as planned.

I want to instruct the user to put the "signature" folder on their desktop, and then run a script that will move all of the items in the signature folder to the AppData folder.

I've been reading, and it looks like it's not as simple as just putting %userprofile%\Desktop\signatures\* into VBScript or PowerShell code. I don't understand why Windows Explorer knows what to do with that path, but PowerShell/VBScript doesn't know what a special folder is, but whatever the case, my code just isn't working.

Here's an example of what I'm trying to do with VBScript:

Dim desktop
Dim appdata
desktop = object.SpecialFolders("Desktop")
appdata = object.SpecialFolders("APPDATA") 

With CreateObject("Scripting.FileSystemObject")
    .MoveFile desktop\MET_Signature_Template\*, appdata\Microsoft\Signatures\test\
End With

I get a syntax error, but no direction on why it's wrong. I've tried a few different things I've found on here to no avail.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
redjax
  • 63
  • 1
  • 6

1 Answers1

1

When in doubt, read the documentation.

Syntax

object.SpecialFolders(objWshSpecialFolders)

Arguments

object
    WshShell object.

Change this:

desktop = object.SpecialFolders("Desktop")
appdata = object.SpecialFolders("APPDATA")

into this:

Set sh  = CreateObject("WScript.Shell")
desktop = sh.SpecialFolders("Desktop")
appdata = sh.SpecialFolders("APPDATA")

Build source and destination paths using the BuildPath method:

Set fso = CreateObject("Scripting.FileSystemObject")
source      = fso.BuildPath(desktop, "MET_Signature_Template")
destination = fso.BuildPath(appdata, "Microsoft\Signatures\test")
fso.MoveFile source & "\*", destination & "\"

In PowerShell you'd do it like this:

$source      = "$env:APPDATA\MET_Signature_Template"
$destination = Join-Path [Environment]::GetFolderPath('Desktop') 'Microsoft\Signatures\test'
Copy-Item "$source\*" $destination
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • Hey, thanks! This worked out fantastic! My problem now is that there's a folder with resources (pictures, etc) for the signature, and that did not get moved. I tried modifying your code to add a "source2" variable with the child folder, and use the same syntax you used but with fso.MoveFolder instead, and it doesn't seem to be working. Any tips on how to move a folder and all of its contents the same way? – redjax Mar 25 '16 at 22:07
  • `MoveFile` moves just files, but `MoveFolder` should move the entire folder including content. Do you get an error? What is the exact path? – Ansgar Wiechers Mar 25 '16 at 22:53