Hi all,
I'm trying to find a nice, simple way to copy the target file of a shortcut, not the shortcut itself. Ultimately I want to be able to copy a folder and all its contents, whether they be shortcuts or 'real' files, to a thumbdrive, etc.
I found a vbscript that does it (see http://groups.google.com/group/microsoft.public.windowsxp.general/msg/f2e8cac8e7870625), but this copies only the shortcut files (not real files in the same folder), and isn't too user-friendly: it needs to be edited for source and destination folders. I don't know anything about WSH, so can someone help with the following?:
1. Make it copy all files in the source folder, not just *.lnk files.
2. Make it ask the user for the source and destination folder. Preferably a nice navigable FileOpen box or whatever, but I suppose a text-only "Enter source path..." type deal would suffice.
3. Or, is there a program out there already that does this?
Here's the code from the above link, just in case:
[fixed]' Note the trailing backslash!
sToFolder = "c:\test\dest\"
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\source"
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[/fixed]
Thanks!
I'm trying to find a nice, simple way to copy the target file of a shortcut, not the shortcut itself. Ultimately I want to be able to copy a folder and all its contents, whether they be shortcuts or 'real' files, to a thumbdrive, etc.
I found a vbscript that does it (see http://groups.google.com/group/microsoft.public.windowsxp.general/msg/f2e8cac8e7870625), but this copies only the shortcut files (not real files in the same folder), and isn't too user-friendly: it needs to be edited for source and destination folders. I don't know anything about WSH, so can someone help with the following?:
1. Make it copy all files in the source folder, not just *.lnk files.
2. Make it ask the user for the source and destination folder. Preferably a nice navigable FileOpen box or whatever, but I suppose a text-only "Enter source path..." type deal would suffice.
3. Or, is there a program out there already that does this?
Here's the code from the above link, just in case:
[fixed]' Note the trailing backslash!
sToFolder = "c:\test\dest\"
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\source"
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[/fixed]
Thanks!