Replacing a Shortcut by a copy of the file to which it is refers ?

K

Kevin Yu

Assume I have a Shortcut to a file. I want to replace it by a copy of the file
to which the Shortcut points. Ok, I could make 10 mouse clicks and drag and & drop and delete old shortcut.
But this is rather inconvenient.

I want to have a command line command which does the job for me in one click.
Later I would set up a context menu entry which I can click to do the job.

Kevin
 
R

Ron Hardin

Well, the link has the directory name and the filename in it, and
presumably you can write a program to extract them (anyway Cygwin
can read it and you can do it there, if you can program), so
you're in business.

But an .exe may not work except in the directory that it lives in,
say it accesses files from the local directory. You would not have
copied them.
 
A

Ayush

[Kevin Yu] wrote-:
Assume I have a Shortcut to a file. I want to replace it by a copy of the file
to which the Shortcut points. Ok, I could make 10 mouse clicks and drag and & drop and delete old shortcut.
But this is rather inconvenient.

I want to have a command line command which does the job for me in one click.
Later I would set up a context menu entry which I can click to do the job.

Try this VBScript :

folder="."

set fs=CreateObject("Scripting.FileSystemObject")
set ws=createobject("wscript.Shell")
Set fl=fs.GetFolder(folder)
n=vbnewline
copiedfiles="Copied files :" &n
For each file in fl.files
If fs.GetExtensionName(file)="lnk" then
pt=file.path
set sc=ws.createshortcut(pt)
path=sc.targetpath
if fs.fileexists(path) then
fs.CopyFile path,fl.path&"\",false
fs.deletefile pt,true
copiedfiles=copiedfiles & "--------" & _
n & pt & n & " - " & path & n
end if
ENd if
Next
if len(copiedfiles) then msgbox copiedfiles



Good Luck, Ayush.
 
A

Ayush

[Kevin Yu] wrote-:
Assume I have a Shortcut to a file. I want to replace it by a copy of the file
to which the Shortcut points. Ok, I could make 10 mouse clicks and drag and & drop and delete old shortcut.
But this is rather inconvenient.
I want to have a command line command which does the job for me in one click.
Later I would set up a context menu entry which I can click to do the job.


Try this VBScript :

folder="."

set fs=CreateObject("Scripting.FileSystemObject")
set ws=createobject("wscript.Shell")
Set fl=fs.GetFolder(folder)
n=vbnewline
copiedfiles="Copied files :" &n
For each file in fl.files
If fs.GetExtensionName(file)="lnk" then
pt=file.path
set sc=ws.createshortcut(pt)
path=sc.targetpath
if fs.fileexists(path) then
fs.CopyFile path,fl.path&"\",false
fs.deletefile pt,true
copiedfiles=copiedfiles & "--------" & _
n & pt & n & " - " & path & n
end if
ENd if
Next
if len(copiedfiles) then msgbox copiedfiles

Good Luck, Ayush.
 
M

Mark F.

Kevin Yu said:
Assume I have a Shortcut to a file. I want to replace it by a copy of the
file
to which the Shortcut points. Ok, I could make 10 mouse clicks and drag
and & drop and delete old shortcut.
But this is rather inconvenient.

I want to have a command line command which does the job for me in one
click.
Later I would set up a context menu entry which I can click to do the job.

Kevin

A shortcut is what it is. A shortcut to a program so you don't have to have
a copy of the actual file everywhere. You can get the command line path of
the shortcut from the "Target" property for the shortcut. Right-click the
shortcut and select "Properties". The "Target" string is the path to the
application, folder, or file.

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top