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

How to extract paths from win9x links (*.lnk files)?

13 views
Skip to first unread message

Peltio

unread,
Oct 26, 2006, 2:23:07โ€ฏPM10/26/06
to
Hi there,

Where can I find information on how to deal with Win9x links?

I'd like to copy al the files linked in a certain (set of) folder(s)
under the Start menu; there are hundreds of links to documents
scattered over 4 hard disks; tracing them one by one can be very
tedious.
So, the bright idea: write a DOS batch file to do that.
The harsh reality is that I have no idea about hot to manage these
*.lnk files in DOS.

Moreover I wanted to recreate the same directory structure of the menu
folder (no great deal) and preserve long filenames.

Any clue?
Is there a supermegaXcopy command that can deal with lnk files,
possibily preserving long filenames?
The switches of xcopy do not seems to help me out of this.

cheers and thanks for any suggestion.
Peltio
(munged address in reply to)

--
Vuoi dare un'occhiata un po' fuori dalla finestra di casa? Su
http://hubblesite.org/gallery/ trovi alcune delle immagini inviate a
terra dal telescopio spaziale Hubble (Annuncio sponsorizzato dalla
LIPSISC)


billious

unread,
Oct 26, 2006, 3:45:18โ€ฏPM10/26/06
to

"Peltio" <pel...@twilight.zone> wrote in message
news:mn.d4c57d6ac...@twilight.zone...
Not really sure what you're trying to achieve.

Are you looking to copy the .LNK files, or the files to which the .LNK
refers?

Superficially, copying the structure would appear to be an application for
XCOPY's /T switch, and LFN preservation is the default. Perhaps the names or
paths contain odd characters like spaces - in which case you should enclose
the source and destination specification in quotes ("source
specification\*.lnk")

Documentation for XCOPY can be obtained from

XCOPY /? |more

from the prompt - the |more because it is more than a page.

But I'll admit to being a bit foggy about what copying the .LNKs would do
to help you.


Peltio

unread,
Oct 26, 2006, 4:43:29โ€ฏPM10/26/06
to
billious wrote

> Not really sure what you're trying to achieve.
>
> Are you looking to copy the .LNK files, or the files to which the .LNK
> refers?

I am trying to copy the files to which the .lnk refer.
For example, suppose I have the following links in the Start menu (just
like in the Recent Files folder in win9x)

Folder1
foo.lnk (pointing to C:\myDocs\foo.doc)
bar.lnk (pointing to D:\download\bar.pdf)
Folder2
oth.lnk (Pointing to E:\oth.txt)

I want to creat a folder Backup on disk F: with the following structure
and content:

F:\Backup\Folder1
foo.doc
bar.pdf
F:\Backup\Folder2
oth.txt)

> Superficially, copying the structure would appear to be an application for
> XCOPY's /T switch, and LFN preservation is the default.

Yes, my problem is how to copy the files to which the .lnk refer and
not the .lnk themselves.
In this way I could back up in one shot all the files whose links I
have sorted during a period of several months.

thanks for your answer, anyway.
cheers,
Peltio

--
Ti sei mai chiesto come funzionano gli oggetti di uso quotidiano? Su
www.howstuffworks.com trovi le spiegazioni. Annuncio sponsorizzato
dalla LIPSISC (Lega Internettiana per la Protezione dei Siti di
Interesse Scientifico Conoscitivo). Aut. Min. rich.


Todd Vargo

unread,
Oct 26, 2006, 5:25:44โ€ฏPM10/26/06
to

"Peltio" <pel...@twilight.zone> wrote in message
news:mn.d4c57d6ac...@twilight.zone...
> Hi there,
>
> Where can I find information on how to deal with Win9x links?
>
> I'd like to copy al the files linked in a certain (set of) folder(s)
> under the Start menu; there are hundreds of links to documents
> scattered over 4 hard disks; tracing them one by one can be very
> tedious.
> So, the bright idea: write a DOS batch file to do that.
> The harsh reality is that I have no idea about hot to manage these
> *.lnk files in DOS.
>
> Moreover I wanted to recreate the same directory structure of the menu
> folder (no great deal) and preserve long filenames.
>
> Any clue?
> Is there a supermegaXcopy command that can deal with lnk files,
> possibily preserving long filenames?
> The switches of xcopy do not seems to help me out of this.
>
> cheers and thanks for any suggestion.

No clue what you are trying to accomplish but if you have "hundreds of links
to documents" in your start menu, then you should reconsider your menu and
storage scheme. Instead, you might create fewer links only to the folders
where many documents reside.

If you really want batch help, consider that providing better details of
what you are trying to do and why helps others understand the task better.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

Peltio

unread,
Oct 26, 2006, 5:46:34โ€ฏPM10/26/06
to
Todd Vargo wrote

> No clue what you are trying to accomplish

I apologize for being unclear.

> but if you have "hundreds of links
> to documents" in your start menu, then you should reconsider your menu and
> storage scheme. Instead, you might create fewer links only to the folders
> where many documents reside.

I have hundreds of docs (papers, tutorials, articles, web pages and
books) and I find it useful to be able to access to them through a
hierarchical directory structure like this

Math
Algebra
Number Theory
Calculus
Functional
Methods
Numerical
Prob Stat
Phy
Mech
Thermo
EM
Statistical
Optics
Quantum
Relativity

and so on.
Each folder contains scores of links (.lnk files) referring to the
actual documents, scattered in different areas of my four disks (some
are in the folder 'books', other are in the 'library' disk, others are
on the 'reference' disk and so on.

And I would like to copy all the files whose links appear in that 'well
ordered' structure on a DVD, mantaing said hierarchical structure.

> If you really want batch help, consider that providing better details of
> what you are trying to do and why helps others understand the task better.

Chopped down to its core, I guess I need a command to extract the full
path of a file from a .lnk oblect.

cheers,
Peltio


--
Ti piace la fisica e vorresti leggere qualche articolo divulgativo di
buon livello? Consulta la sezione "Best of" di Physics World alla
pagina http://physicsweb.org/bestof/ (Comunicato a cura della LIPSISC)


Ben Myers

unread,
Oct 26, 2006, 9:59:05โ€ฏPM10/26/06
to
Please repost with more information, including the name of the file
containing the drive, path and filenames of the shortcuts, or the
method or technique you plan to use to get this information.

Ben

"Peltio" <pel...@twilight.zone> wrote in message news:mn.d4c57d6ac...@twilight.zone...

foxidrive

unread,
Oct 26, 2006, 11:10:39โ€ฏPM10/26/06
to

There was a message with utility posted in the last few months (I think)
either in alt.msdos.batch or alt.msdos.batch.nt which parses the .lnk
files. Someone else needed to extract info from link files.

Todd Vargo

unread,
Oct 27, 2006, 12:25:53โ€ฏAM10/27/06
to

"Peltio" <pel...@twilight.zone> wrote in message
news:mn.d5907d6a8...@twilight.zone...

This information (and that in your other reply is useful. Unfortunately,
there is no single command to do what you want however, you can create a
batch of commands to accomplish your goal.

The following batch is for Windows 98 with Windows Scripting Host 5.6
installed. To use it, you set the name of the destination you want in the
second line (must be enclosed in quotes as shown). Then save the batch in
the start menu folder (i.e. Math) you want to copy the files from within the
links and run it. If it does what wanted, repeat for any other folders you
want the backup this way.

@echo off
set destination="e:\backup\folder\"
echo> tmp.vbs set WshShell = WScript.CreateObject("WScript.Shell")
echo>>tmp.vbs Do While Not Wscript.StdIn.AtEndOfStream
echo>>tmp.vbs lnk = Wscript.StdIn.ReadLine
echo>>tmp.vbs Set oLink = WshShell.CreateShortcut(lnk)
echo>>tmp.vbs cmd = "xcopy " & Chr(34) & oLink.TargetPath & Chr(34)
echo>>tmp.vbs cmd = cmd & " " & Chr(34) & %destination% & Chr(34)
echo>>tmp.vbs cmd = cmd & " /d/f"
echo>>tmp.vbs Wscript.Echo cmd
echo>>tmp.vbs Set oLink = Nothing
echo>>tmp.vbs Loop
dir /b *.lnk | cscript /nologo tmp.vbs > tmp.bat
del tmp.vbs
call tmp.bat
del tmp.bat

Peltio

unread,
Oct 30, 2006, 7:16:05โ€ฏPM10/30/06
to
Todd Vargo wrote:

> The following batch is for Windows 98 with Windows Scripting Host 5.6
> installed. To use it, you set the name of the destination you want in the
> second line (must be enclosed in quotes as shown). Then save the batch in
> the start menu folder (i.e. Math) you want to copy the files from within the
> links and run it. If it does what wanted, repeat for any other folders you
> want the backup this way.
>
> @echo off
> set destination="e:\backup\folder\"
> echo> tmp.vbs set WshShell = WScript.CreateObject("WScript.Shell")
> echo>>tmp.vbs Do While Not Wscript.StdIn.AtEndOfStream
> echo>>tmp.vbs lnk = Wscript.StdIn.ReadLine
> echo>>tmp.vbs Set oLink = WshShell.CreateShortcut(lnk)
> echo>>tmp.vbs cmd = "xcopy " & Chr(34) & oLink.TargetPath & Chr(34)
> echo>>tmp.vbs cmd = cmd & " " & Chr(34) & %destination% & Chr(34)
> echo>>tmp.vbs cmd = cmd & " /d/f"
> echo>>tmp.vbs Wscript.Echo cmd
> echo>>tmp.vbs Set oLink = Nothing
> echo>>tmp.vbs Loop
> dir /b *.lnk | cscript /nologo tmp.vbs > tmp.bat
> del tmp.vbs
> call tmp.bat
> del tmp.bat

Thanks a lot. It does what you say and it's a big step forward toward
the final goal (or, as Armstrong would have put it: "it's a small step
for Todd, yet a giant leap for Peltkind").

It does not act on nested directories, as expected.
Yet it shows an undesired behavior when it encounters a shortcut to a
directory [1]. In that case it copies only the files [2] contained in
the linked directory (and that is good) without creating the
corresponding directory (and that's not good).

I am pretty new to this WSH thing (even though I already had version
5.6 installed on my system) and now I have to study a little Visual
Basic in order to automate this task.
I guess two steps are necesary:

a) using VB to process the shortcuts' directory tree and create a twin
tree in e:\backup (not exactly a twin, though: I might need to create a
real folder when there's a shortcut to a folder [2])
b) --- this is thougher than I had thought :-)
either
Writing a script that copies your bat file into every
folder of the shortcuts' tree and executes it
or
Writing a script that creates a bat file with xcopy
statements for every directory of the shortcuts' tree
or
I might as well write a full fledged C program, at this point. :-(

At any rate, thanks for the starter.

cheers,
Peltio

[1] Something I did not say before, thinking it was not important, is
that the menu structure is nested, i.e. I can have nested directories

Library
Math
Algebra
Linear Algebra
Abstract Algebra
Calculus
Differential
Integral
...
Phy
...

each of which can contain shortcuts either to files or directories
(i.e. a web site mirror with html files, pictures and all the stuff).

[2] I guess that adding a switch to xcopy in order will allow to make
it copy nested dirs. I'm off to do some experiments, now.

Todd Vargo

unread,
Oct 31, 2006, 12:57:00โ€ฏAM10/31/06
to

"Peltio" <pel...@twilight.zone> wrote in message
news:mn.f84b7d6ac...@twilight.zone...

> Todd Vargo wrote:
>
> > The following batch is for Windows 98 with Windows Scripting Host 5.6
> > installed. To use it, you set the name of the destination you want in
the
> > second line (must be enclosed in quotes as shown).
snip...

> It does not act on nested directories, as expected.
> Yet it shows an undesired behavior when it encounters a shortcut to a
> directory [1]. In that case it copies only the files [2] contained in
> the linked directory (and that is good) without creating the
> corresponding directory (and that's not good).

Sorry, I can only work with what I am aware of.

You may wish to try this minor adjustment first. I think this batch will do
what are asking. You can save it anywhere but you have to set the source and
destination directories before use. Remember to keep the trailing backslash
on each when you change them. Let us know how this works out for you.

@echo off
set source="c:\windows\start menu\Programs\Library\"
set destination="e:\backup\Library\"


echo> tmp.vbs set WshShell = WScript.CreateObject("WScript.Shell")

echo>>tmp.vbs source = %source%


echo>>tmp.vbs Do While Not Wscript.StdIn.AtEndOfStream
echo>>tmp.vbs lnk = Wscript.StdIn.ReadLine

echo>>tmp.vbs src = Replace(lnk, source, "", 1, 1, 1)
echo>>tmp.vbs src = %destination% & Left(src, InStrRev(src, "\"))


echo>>tmp.vbs Set oLink = WshShell.CreateShortcut(lnk)
echo>>tmp.vbs cmd = "xcopy " & Chr(34) & oLink.TargetPath & Chr(34)

echo>>tmp.vbs cmd = cmd & " " & Chr(34) & src & Chr(34)


echo>>tmp.vbs cmd = cmd & " /d/f"
echo>>tmp.vbs Wscript.Echo cmd
echo>>tmp.vbs Set oLink = Nothing
echo>>tmp.vbs Loop

dir /a-d /b /s %source%*.lnk | cscript /nologo tmp.vbs > tmp.bat


del tmp.vbs
call tmp.bat
del tmp.bat

--

Peltio

unread,
Oct 31, 2006, 8:49:08โ€ฏPM10/31/06
to
Todd Vargo wrote:

> Let us know how this works out for you.
>
> @echo off
> set source="c:\windows\start menu\Programs\Library\"
> set destination="e:\backup\Library\"
> echo> tmp.vbs set WshShell = WScript.CreateObject("WScript.Shell")
> echo>>tmp.vbs source = %source%
> echo>>tmp.vbs Do While Not Wscript.StdIn.AtEndOfStream
> echo>>tmp.vbs lnk = Wscript.StdIn.ReadLine
> echo>>tmp.vbs src = Replace(lnk, source, "", 1, 1, 1)
> echo>>tmp.vbs src = %destination% & Left(src, InStrRev(src, "\"))
> echo>>tmp.vbs Set oLink = WshShell.CreateShortcut(lnk)
> echo>>tmp.vbs cmd = "xcopy " & Chr(34) & oLink.TargetPath & Chr(34)
> echo>>tmp.vbs cmd = cmd & " " & Chr(34) & src & Chr(34)
> echo>>tmp.vbs cmd = cmd & " /d/f"
> echo>>tmp.vbs Wscript.Echo cmd
> echo>>tmp.vbs Set oLink = Nothing
> echo>>tmp.vbs Loop
> dir /a-d /b /s %source%*.lnk | cscript /nologo tmp.vbs > tmp.bat
> del tmp.vbs
> call tmp.bat
> del tmp.bat

Thanks for your help.

The first time I ran it I forgot the backslash at the end of the source
path. I got two error messages: one that told me I had run out of my
environment space) and a syntax error in tmp.vbs.
When I ran it again (with the missing \) it crashed my system (BSOD on
Win98SE).

After rebooting, I modified the bat file REMming out the lines that
deleted the tmp files. I discovered that tmp.vbs lacked any refererence
to the destination folder. And this caused the syntax error. This is
the actual tmp.vbs file created:

set WshShell = WScript.CreateObject("WScript.Shell")

source = "D:\OSData\Desk2\folder\"
Do While Not Wscript.StdIn.AtEndOfStream
lnk = Wscript.StdIn.ReadLine


src = Replace(lnk, source, "", 1, 1, 1)

src = & Left(src, InStrRev(src, "\"))
Set oLink = WshShell.CreateShortcut(lnk)


cmd = "xcopy " & Chr(34) & oLink.TargetPath & Chr(34)

cmd = cmd & " " & Chr(34) & src & Chr(34)

cmd = cmd & " /d/f"

Wscript.Echo cmd
Set oLink = Nothing
Loop

and this of course is what caused the syntax error

src = & Left(src, InStrRev(src, "\"))

Inferring that destination had to be set to the value of the
environmental variable destination [1], I added a line

> echo>>tmp.vbs destination = %destination%

But the tmp.vbs file did not seem to appreciated it much. I simply
anticipated the error to line 3 :-)

set WshShell = WScript.CreateObject("WScript.Shell")

source = "D:\OSData\Desk2\folder\"
destination =
Do While Not Wscript.StdIn.AtEndOfStream
lnk = Wscript.StdIn.ReadLine


src = Replace(lnk, source, "", 1, 1, 1)

src = & Left(src, InStrRev(src, "\"))
Set oLink = WshShell.CreateShortcut(lnk)


cmd = "xcopy " & Chr(34) & oLink.TargetPath & Chr(34)

cmd = cmd & " " & Chr(34) & src & Chr(34)

cmd = cmd & " /d/f"

Wscript.Echo cmd
Set oLink = Nothing
Loop

How do I pass the destination path to the script?

cheers,
Peltio

[1] I am still at an early stage of my "VBScript for complete braindead
idiots" studying.

Peltio

unread,
Oct 31, 2006, 9:26:02โ€ฏPM10/31/06
to
>> set source="c:\windows\start menu\Programs\Library\"
>> set destination="e:\backup\Library\"


Appereantly the problem was in the lenght of "destination".
I changed it to "dest" and the vbs stopped showing syntax errors.
And, lo!

It works!
Files are copied. And shortcuts to folders cause the entire folder to
be copied (I've tested it with only one level of nesting so far)

Thanks a lot, Todd.

Peltio

--
Vuoi vedere come รจ fatto un brevetto? Su www.patentstorm.us trovi una
montagna di brevetti americani, ordinati per categoria. Annuncio

Todd Vargo

unread,
Oct 31, 2006, 11:42:22โ€ฏPM10/31/06
to

"Peltio" <pel...@twilight.zone> wrote in message
news:mn.08cd7d6b1...@twilight.zone...

> >> set source="c:\windows\start menu\Programs\Library\"
> >> set destination="e:\backup\Library\"
>
>
> Appereantly the problem was in the lenght of "destination".
> I changed it to "dest" and the vbs stopped showing syntax errors.
> And, lo!
>
> It works!
> Files are copied. And shortcuts to folders cause the entire folder to
> be copied (I've tested it with only one level of nesting so far)
>
> Thanks a lot, Todd.

Excellent, you found the problem. Your environment was exhausted by just a
few characters. Adding the following line to your config.sys file and
rebooting will increase the standard environment size to 4096 bytes. That is
more than enough environment space for future batch files to have plenty of
environment space.

shell=command.com /e:4096 /p


Another (less permanent) fix is to increase the environment size on the fly.
This increased environment applies to this batch only.

@echo off
if %1.==. command /e:4096 /c %0 ::
if %1.==. goto :eof


set source="c:\windows\start menu\Programs\Library\"
set destination="e:\backup\Library\"

echo> tmp.vbs set WshShell = WScript.CreateObject("WScript.Shell")
echo>>tmp.vbs source = %source%
echo>>tmp.vbs Do While Not Wscript.StdIn.AtEndOfStream
echo>>tmp.vbs lnk = Wscript.StdIn.ReadLine
echo>>tmp.vbs src = Replace(lnk, source, "", 1, 1, 1)
echo>>tmp.vbs src = %destination% & Left(src, InStrRev(src, "\"))
echo>>tmp.vbs Set oLink = WshShell.CreateShortcut(lnk)
echo>>tmp.vbs cmd = "xcopy " & Chr(34) & oLink.TargetPath & Chr(34)
echo>>tmp.vbs cmd = cmd & " " & Chr(34) & src & Chr(34)
echo>>tmp.vbs cmd = cmd & " /d/f"
echo>>tmp.vbs Wscript.Echo cmd
echo>>tmp.vbs Set oLink = Nothing
echo>>tmp.vbs Loop
dir /a-d /b /s %source%*.lnk | cscript /nologo tmp.vbs > tmp.bat
del tmp.vbs
call tmp.bat
del tmp.bat

:eof

0 new messages