E
Ed
Hello,
I posted a message recently asking for help to copy files pointed to by
links to another destination and got a response directing me to the VBScript
listed below. It works, but has hardcoded source and destination
directories. Is it possible to modify this script so that it accepts two
command line arguments specifying the source and destination directories?
If so, how? Is it also possible to create a version of this script that can
be run without a command line, perhaps where I drag the source LNK files to
the script icon, causing it to run and copy the files pointed to by the
dragged LNK files to a destination directory hardcoded in the script? Is
there an even easier way to do this that I am missing?
Thanks for your help!
Ed Self
~~~~~~~~~~~~~~~~~~~~~~
sToFolder = "c:\test\backup\"
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
' If the files exist in the folder from before (from a previous run),
' none of them must be RO or the script below will err. To avoid this,
' script runs the attrib command to remove any RO flags.
oShell.Run "attrib.exe /s -r " & sToFolder & "*", 0, True
' Using the desktop folder as an example
'sFolderWithLinks = oShell.SpecialFolders("Desktop")
' For a hard coded path, uncomment the following line and edit the path
sFolderWithLinks = "c:\test"
Set oFiles = oFSO.GetFolder(sFolderWithLinks).Files
For Each oFile In oFiles
If LCase(oFSO.GetExtensionName(oFile)) = "lnk" Then
Set oShellLink = oShell.CreateShortcut(oFile.Path)
sLinkTargetPath = oShellLink.TargetPath
If oFSO.FileExists(sLinkTargetPath) Then
oFSO.CopyFile sLinkTargetPath, sToFolder, True
End If
End If
Next
I posted a message recently asking for help to copy files pointed to by
links to another destination and got a response directing me to the VBScript
listed below. It works, but has hardcoded source and destination
directories. Is it possible to modify this script so that it accepts two
command line arguments specifying the source and destination directories?
If so, how? Is it also possible to create a version of this script that can
be run without a command line, perhaps where I drag the source LNK files to
the script icon, causing it to run and copy the files pointed to by the
dragged LNK files to a destination directory hardcoded in the script? Is
there an even easier way to do this that I am missing?
Thanks for your help!
Ed Self
~~~~~~~~~~~~~~~~~~~~~~
sToFolder = "c:\test\backup\"
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
' If the files exist in the folder from before (from a previous run),
' none of them must be RO or the script below will err. To avoid this,
' script runs the attrib command to remove any RO flags.
oShell.Run "attrib.exe /s -r " & sToFolder & "*", 0, True
' Using the desktop folder as an example
'sFolderWithLinks = oShell.SpecialFolders("Desktop")
' For a hard coded path, uncomment the following line and edit the path
sFolderWithLinks = "c:\test"
Set oFiles = oFSO.GetFolder(sFolderWithLinks).Files
For Each oFile In oFiles
If LCase(oFSO.GetExtensionName(oFile)) = "lnk" Then
Set oShellLink = oShell.CreateShortcut(oFile.Path)
sLinkTargetPath = oShellLink.TargetPath
If oFSO.FileExists(sLinkTargetPath) Then
oFSO.CopyFile sLinkTargetPath, sToFolder, True
End If
End If
Next