I work for quite a time with windows and I really hate to ask the
following question, but: I have very simple problem I found really no
easy solution to using the tools included in windows - maybe you can
help me to find the right tool for the job:
Given I have a folder with lots of links (about 1000) to files on
another disk and now I want to copy all the real files the links point
to, to a different disk. How to do that? When I select and copy the
links and paste them to the new disk the links are getting copied
(like expected) instead of the files.
How to copy the files? I appreciate any help!
Ciao, Bernd
Hi
Below is a vbscript as a starting point (put it in a text file with the
extension .vbs).
WSH 5.6 documentation (local help file) can be downloaded from here:
http://msdn.microsoft.com/downloads/list/webdev.asp
All files will be copied into the folder in the variable sToFolder flat, not
obtaining their folder structure. This can be changed, but it will complicate
the script somewhat. As the script is now, the folder must exist or the script
will err.
' Note the trailing backslash!
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 = "i:\projects"
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
--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter
thanks a lot for the nice trick, it works like a charm - the copying
of all the files took a while<g>. Never tried the scripting host - now
I'll check the WSH link you mentioned.
Ciao, Bernd
"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message news:<3EA37F86...@hydro.com>...