This is related to this idea, so i figured i'd post it here in case somebody might find it useful. It is related in that it does the opposite of what you want.
It takes a folder of shortucts and copies the actual files over to a destination of your choice.
here's the code for it, it's a vb script. so save it as .vbs and pass it the correct parameters to run it.
'
'
CopyShortcutTargets.vbs
'
' Purpose: A simple Synchronization/Multiple Folder to One Folder
' script.
' Create a directory full of shortcuts to programs/files/folders
' that you want to copy to a destination folder
' Run this script either
' a) from that directory with the destination folder as a parameter
' b) from anywhere with the destination folder as the 1st parameter
'
and the source folder (with the shortcuts in it) as the second
'
parameter
'
' Notes: WARNING - Will overwrite files without prompting!
' If you make changes please send me email, might go to spam, so
' be careful :)
'
'
Written by Vixay Xavier,
'
Version 1.0 -
[email protected]' Remove IGNORE THIS from email address before mailing it out
' Don't know how effective this is but eh, it's worth a shot :)
'
' Source/Help taken from:
' === "bertha_index.vbs"
'
Keep Bertha Surfin Heavy Industries,
'
a division of Keep Bertha Surfin Electrical Concern
'
Version 1.0 -
[email protected]' === "LogToFile.vbs"
' http://www.naterice.com/blog/template_permalink.asp?id=43
'TODO
' Add better error handling/notification
'
- for overwriting scenario
'
- when logfile doesn't exist/ can't create
' Keep statistics?
'DONE
' Add Logging to Source Directory of Files Copied and all - Done
' Notification to user while running - changed method to windows
' copy box, and added a done dialog box at end. This makes the script
' unusable in automated fashion, but easy enough to fix by
' removing/commenting out the "msgbox" line
Option Explicit
'---------LogToFile Configuration---------
'NOTE: Copy the configuration section To
'the beginning of an existing script. The
'values specified here must be set before
'calling the LogToFile sub.
Dim bEnableLogging
Dim bIncludeDateStamp
Dim bPrependDateStampInLogFileName
Dim sLogFileLocation
Dim sLogFileName
Dim sOverWriteORAppend
'You can disable logging globally by
'setting the bEnableLogging option to false.
bEnableLogging = True
'Setting this to true will time stamp Each
'message that is logged to the log file
'with the current date and time.
bIncludeDateStamp = True
'This will set the log file name to the
'current date and time. You can use this
'option to create incremental log files.
bPrependDateStampInLogFileName = True
'Specify the log file location here. Path
'must contain a trailing backslash. If you
'would like to log to the same location as
'the currently running script, set this
'value to "relative" or uncomment out the
'line below.
'sLogFileLocation = "C:\LogFiles\"
sLogFileLocation = "relative"
'Specify the log file name here.
sLogFileName = "CopyTargets.log"
'You can set whether or not you would like
'the script to append to an existing file,
'or if you would like it to overwrite
'existing copies. To overwrite set the
'sOverWriteORAppend variable to "overwrite"
sOverWriteORAppend = "append"
'-------END LogToFile Configuration-------
' Run the Function :)
Call CheckParameters
Sub CheckParameters()
' First thing, check the argument list for a directory.
' If they didn't specIfy one, use the current directory.
Dim fso
Set fso = createobject("scripting.filesystemobject")
Dim destF
Dim sourceF
If WScript.Arguments.Count = 0 Then
WScript.Echo "Error: No Destination folder provided!" & vbcrlf _
& "Usage: Scriptname DestFolder [SourceFolder]" & vbcrlf _
& " SourceFolder is assumed to be current directory when ommitted"
'If not Destination is provided quit
WScript.Quit
ElseIf Wscript.Arguments.Count = 1 Then
' if 1 argument is provided ASSUME it's destination folder
destF = WScript.Arguments(0)
sourceF = fso.GetAbsolutePathName(".")
ElseIf Wscript.Arguments.Count = 2 Then
' if 2 arguments are provided ASSUME 1st is destination folder
' and 2nds is source folder
destF = WScript.Arguments(0)
sourceF = WScript.Arguments(1)
End If
GetWorkingFolder destF, sourceF
Set fso = nothing
End Sub
Function GetWorkingFolder(targetF, originF)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim sourceF
Set sourceF = fso.GetFolder(originF)
Dim destF
If Not fso.FolderExists(targetF) Then
fso.CreateFolder(targetF)
End If
Set destF = fso.GetFolder(targetF)
Dim sourceFiles
Set sourceFiles = sourceF.Files
Dim remaincount
remaincount = sourceFiles.count
LogToFile("Process Started" & vbcrlf _
& "Source: " & sourceF & vbcrlf _
& "Destination: " & destF & vbcrlf _
& "# of Files in Source:" & remaincount)
Dim file_in_f
Dim ftemp
Dim targt
Dim fsCopyObj
'***Code to test windows animated copying method
Dim shAppObj, nmSpObj
Set shAppObj = CreateObject("Shell.Application")
Set nmSpObj = shAppObj.NameSpace(destF.Path)
'***End test code setup
For each file_in_f in sourceFiles
Set ftemp = fso.GetFile(file_in_f.Name)
'If file is a shortcut
If fso.GetExtensionName(ftemp) = "lnk" Then
'This is where the magic happens
' 1) we get the target path
' 2) check what it is
' 3) copy it to destination
'Find it's target
targt = FindTarget(file_in_f.Name)
'Check if it's a folder/file
If (fso.FolderExists(targt)) Then
LogToFile(" Copying directory- " & targt)
Set fsCopyObj = fso.GetFolder(targt)
'fso.CopyFolder targt, destF
ElseIf (fso.FileExists(targt)) Then
LogToFile(" Copying file - " & targt)
Set fsCopyObj = fso.GetFile(targt)
'fso.CopyFile targt, destF
Else
LogToFile(" ERROR: Cannot determine targets type - " & targt)
End If
'And Copy the target to destination
If Not fsCopyObj is Nothing Then
'Wscript.Echo "Copying to " & destF.Path
'fsCopyObj.Copy destF.Path & "\"
'*** Alternative Windows animated method
'See http://www.tek-tips.com/viewthread.cfm?qid=831585
nmSpObj.CopyHere fsCopyObj.Path,16
'*** End alternative method
Set fsCopyObj = Nothing
End If
End If
Set ftemp = Nothing
Next
LogToFile("Done copying files/folders")
If MsgBox("Done copying files/folders." & vbcrlf _
& "Log Filename: " & sLogFileName & vbcrlf _
& "Open Log?", vbYesNo + vbQuestion, "Done, Open Log?") = vbYes Then
Set shAppObj = nothing
Set shAppObj = CreateObject("WScript.Shell")
shAppObj.Run "notepad " & sLogFileLocation & sLogFileName
End If
Set shAppObj = nothing
Set nmSpObj = nothing
Set fso = nothing
Set sourceF = nothing
Set destF = nothing
Set sourceFiles = nothing
Exit Function
errHandler:
End Function
Function FindTarget(filenam)
Dim shortct, WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
Set shortct = WshShell.CreateShortcut(filenam)
FindTarget = shortct.TargetPath
Set WshShell = nothing
Set shortct = nothing
End Function
Sub LogToFile(sMessage)
'LogToFile.vbs 12-15-06
'This script is provided under the Creative Commons license located
'at http://creativecommons.org/licenses/by-nc/2.5/ . It may not
'be used for commercial purposes with out the expressed written consent
'of NateRice.com
If bEnableLogging = False Then Exit Sub
Dim oLogFSO
Dim oLogShell
Dim oLogFile
Dim sNow, sLogFile
Const ForWriting = 2
Const ForAppending = 8
Set oLogFSO = CreateObject("Scripting.FileSystemObject")
If sLogFileLocation = "relative" Then
Set oLogShell = CreateObject("Wscript.Shell")
sLogFileLocation = oLogShell.CurrentDirectory & "\"
Set oLogShell = Nothing
End If
If bPrependDateStampInLogFileName Then
sNow = Replace(Replace(Now(),"/","-"),":",".")
sLogFileName = sNow & " - " & sLogFileName
'Disable generation of another logfilename for subsequent calls
bPrependDateStampInLogFileName = False
End If
sLogFile = sLogFileLocation & sLogFileName
If sOverWriteORAppend = "overwrite" Then
Set oLogFile = oLogFSO.OpenTextFile(sLogFile, ForWriting, True)
sOverWriteORAppend = "append"
Else
Set oLogFile = oLogFSO.OpenTextFile(sLogFile, ForAppending, True)
End If
If bIncludeDateStamp Then
sMessage = Now & " " & sMessage
End If
oLogFile.WriteLine(sMessage)
oLogFile.Close
oLogFSO = Null
End Sub