Word2003/VBA FileLen of a shortcut link

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Word2003/VBA FileLen of a shortcut link

Post by ChrisGreaves »

Untitled.png
My guess is that a shortcut link that goes by the name of "Everything-1.2.1.371.exe - Shortcut" isn't really a file, even though it appears within a folder. It is instead a place-holder.

The analogy would be a business card, a piece of cardboard about 3x2 inches.
The business card represents the person, has their name, address and so on, but bears no real physical resemblance to a person.
So that while I can use the data on the card to communicate with that person, it makes no sense to ask "How tall is the business card?", because a business card is not an object that can be said to be "tall"; it is merely a place holder for the real person.

In that sense the FileLen function is not meant to be applied to a Windows Explorer shortcut link to a real file.
before I test the FileLen of a file I should test to see if the nominated file is a shortcut link.

The attached function is one I borrowed a long time ago from MarkD
''' FROM A POST MADE BY MarkD [Post: 577,070]
''' http://www.wopr.com/cgi-bin/w3t/showthr ... 5&o=0&vc=1

Cheers
Chris
You do not have the required permissions to view the files attached to this post.
An expensive day out: Wallet and Grimace

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Word2003/VBA FileLen of a shortcut link

Post by HansV »

The old Woody's Lounge www.wopr.com is long gone...

What happens if you change the file name in strFileName from "Everything-1.2.1.371.exe - Shortcut" to "Everything-1.2.1.371.exe - Shortcut.lnk" ? Shortcuts have a hidden extension .lnk
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Word2003/VBA FileLen of a shortcut link

Post by ChrisGreaves »

HansV wrote:
23 Feb 2021, 20:59
The old Woody's Lounge www.wopr.com is long gone...
Thanks Hans. Bad enough that the snow is falling just two hours after I finished clearing the last lot out of my path ... then you have to remind me that ... (grin)
What happens if you change the file name in strFileName from "Everything-1.2.1.371.exe - Shortcut" to "Everything-1.2.1.371.exe - Shortcut.lnk" ? Shortcuts have a hidden extension .lnk
I dunno!
With 141,792 files on this data partition alone, let alone the C-drive, plus two other laptops and a motley crew of USB backup drives, and our six-hour summer just five months away, I am not in the business of renaming files manually. And the process can't be fully automated because, you see, the files do not exist (according to some part of MS software)

This "illegal file names" project started because I could not complete my "Duplicates" project, because the file names (MP3 in one case) which load into my string Array are sometimes illegal.

This morning I reduced a list of 429 illegal files names down to 180, just by ignoring shortcut links. This and some other filters will become a run-time option in my utility that builds arrays of file names.

Next Tuesday (Tuesday is "illegals day") I will determine a few more filters, and then start renaming the hard-to-budge guys so that every project can run on a file array without a File Not Found error.

Cheers
Chris
An expensive day out: Wallet and Grimace

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Word2003/VBA FileLen of a shortcut link

Post by HansV »

I didn't mean that you should change the name of the file on your hard disk! Only to add .lnk in the code...
As an experiment, try the following:

Code: Select all

Sub Test()
    Dim strFileName As String
    ' Complete the path as needed
    strFileName = "T:\Appl\Everything\...\Everything-1.2.1.371.exe - Shortcut.lnk"
    Debug.Print FileLen(stgrFileName)
End Sub
(I cannot see the entire path in your screenshot, so I used ...)

Do you get the same error message?
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Word2003/VBA FileLen of a shortcut link

Post by ChrisGreaves »

HansV wrote:
23 Feb 2021, 23:22
I didn't mean that you should change the name of the file on your hard disk! Only to add .lnk in the code...
Thanks, Hans. I'll give this a try and report back.

The Bottom line is still the matter of what MS will reveal to the VBA user.
In a specific case, I ask (FSO) for the names of all the files (not folders) within a folder Tree T:\Music\, and I store those names in a string Array (18,000 entries).
If/When MS gives me a filename with a foreign character, or a CHRW(-4062) or a missing ".lnk" I can do nothing about that. Likewise if some clown updates a Del Shannon hit from the 60s under the name "Bach Cantata BWV001in B-Flat", I can only deal with what I'm given.

So if a filename from that array returns File Not Found" when Filelen(), FileDateTime() or Kill etc are applied, there's not a lot that I can do in terms of automatic, unattended operation. Rename is another useless function in these cases.

In the example I gave, the string "Shortcut" in the name was a visual clue for this old brain, and implementing a content test lets me avoid what to me are useless file names - when searching for duplicate music tracks, or when searching for files that might contain VBA code, or whatever the project happens to be. Of course if I wanted to search the 141,792 files for broken shortcut links, I should still test the content of every file for that 40-byte tag, because after all who knows what some user has/has not done to mangle file names!

Cheers
Chris
An expensive day out: Wallet and Grimace

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15498
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Word2003/VBA FileLen of a shortcut link

Post by ChrisGreaves »

HansV wrote:
23 Feb 2021, 20:59
What happens if you change the file name in strFileName from "Everything-1.2.1.371.exe - Shortcut" to "Everything-1.2.1.371.exe - Shortcut.lnk" ? Shortcuts have a hidden extension .lnk
Well! That didn't take long, did it? Another week, another snowstorm ...
I tripped myself up on several counts:-

(1) This year I am using both Everything.exe and Windows File Explorer to work with Illegal filenames.
Illeg001.png
EverryThing.exe shows me the link file with the extension LNK in place.
When I right-click on that name and "Open Path" ...
Illeg002.png
Windows File Explorer shows me the file name without the LNK extension.

Since I am flipping back and forth between Everything and Explorer (well, the FSO actually, which amounts to the same thing), I am using two different forms of the same name - one with the LNK and one without.

(2) MarkD's analysis of the leading 20 bytes is still correct of course, but in my code I was stripping two bytes off this data. Don't ask me why.
Left$(Right$(strFileData, Len(strFileData) - 2), Len(strMask))

(3) My original nested IF statement was incorrect. Now it is working but it is uglier (I must streamline it)

(4) I did not have in place your trick of seeing if adding the LNK extension helped.

(5) The call to DumpFileData should be disabled; I left it in the attached code in case anyione wants to see the decimal values.

Apart from that, everything (sorry!) is just fine!
Cheers
Chris
You do not have the required permissions to view the files attached to this post.
An expensive day out: Wallet and Grimace