Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Copying files behind links

820 views
Skip to first unread message

Bernd Kunrath

unread,
Apr 19, 2003, 12:12:47 PM4/19/03
to
Hi all,

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

Torgeir Bakken (MVP)

unread,
Apr 21, 2003, 1:20:12 AM4/21/03
to
Bernd Kunrath wrote:

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


Bernd Kunrath

unread,
Apr 21, 2003, 10:09:34 AM4/21/03
to
Hi Torgeir,

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>...

minhe...@gmail.com

unread,
Sep 30, 2015, 12:53:32 AM9/30/15
to
I tried this and it worked for only 3 out of the 20 shortcuts that had in my folder for testing. Why does it skip some shortcuts? Any idea?

Paul

unread,
Sep 30, 2015, 4:50:04 AM9/30/15
to
When a script doesn't do what you expected, you can investigate
in the same way as some C programmers would. A trained programmer
might use the IDE debugger to figure out what is going on. Whereas
home-schooled programmers use "printf" and they print the values
of things within their program. If you expect to use a scripting
language (and use half-finished example scripts which are not
thoroughly defensively programmed), then having a printf method
is a good idea.

So first you find some examples of doing output to the console.
Or at least try to find a method.

http://stackoverflow.com/questions/4388879/vbscript-output-to-console

WScript.Echo "Output some text"

Then, there is another example here, when I try to learn the
canonical form for if-then-else construct. For our purposes
we don't need the ElseIf clauses, and a simple if-then-else-endif
is sufficient.

http://www.tizag.com/vbscriptTutorial/vbscriptelseif.php

If temperature > 70 Then
document.write("Wear a T-Shirt!")
ElseIf temperature > 60 Then
document.write("Wear a hat!")
ElseIf temperature > 50 Then
document.write("Wear a long-sleeved shirt!")
Else
document.write("Wear a coat!")
End If

You could modify the script, to make the script explain
it has skipped some items. Then look at the values.

If oFSO.FileExists(sLinkTargetPath) Then
oFSO.CopyFile sLinkTargetPath, sToFolder, True
Else
document.write(sLinkTargetPath)
End If

Now, I'm not going to play with the script for you,
and you can experiment with the script yourself. Trying
the stuff out, is the fastest way to become an expert like
the Norwegian MVP.

Since the script uses FileExists(sLinkTargetPath), it is
evaluating whether there is something to copy or not. And
the script skips to the next item, if that requirement is
not met. Thus, you need to print out the value of
sLinkTargetPath and see whether it is valid or not.
If sLinkTargetPath is actually a command of some sort,
it might be quite a long line of (irrelevant) text.

Paul
0 new messages