From a86f953303a0fe3379643b0de42d98c655c13942 Mon Sep 17 00:00:00 2001 From: Martin Grottenthaler <9715799+mgrottenthaler@users.noreply.github.com> Date: Thu, 7 Aug 2025 12:54:07 +0200 Subject: [PATCH 1/3] change detection of entry_type, fix for linux --- pylnk3.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pylnk3.py b/pylnk3.py index f037c90..250697b 100644 --- a/pylnk3.py +++ b/pylnk3.py @@ -586,9 +586,9 @@ def __init__(self, bytes=None): version_offset = read_short(buf) @classmethod - def create_for_path(cls, path): + def create_for_path(cls, path, entry_type): entry = cls() - entry.type = os.path.isdir(path) and TYPE_FOLDER or TYPE_FILE + entry.type = entry_type try: st = os.stat(path) entry.file_size = st.st_size @@ -1803,7 +1803,11 @@ def for_file( elements = [RootEntry(ROOT_MY_COMPUTER), DriveEntry(levels[0])] for level in levels[1:]: - segment = PathSegmentEntry.create_for_path(level) + # set TYPE_FOLDER by default, unless it's the last entry (which is the file) + entry_type = TYPE_FOLDER + if level == levels[-1]: + entry_type = TYPE_FILE + segment = PathSegmentEntry.create_for_path(level, entry_type) elements.append(segment) lnk.shell_item_id_list = LinkTargetIDList() lnk.shell_item_id_list.items = elements From 884a0f337d7b6f721e15f3c8f546c5385cbf15a7 Mon Sep 17 00:00:00 2001 From: Martin Grottenthaler <9715799+mgrottenthaler@users.noreply.github.com> Date: Thu, 7 Aug 2025 12:59:50 +0200 Subject: [PATCH 2/3] add info on entry types to parse output --- pylnk3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylnk3.py b/pylnk3.py index 250697b..163f721 100644 --- a/pylnk3.py +++ b/pylnk3.py @@ -690,7 +690,7 @@ def bytes(self): return out.getvalue() def __str__(self): - return "" % self.full_name + return f"" class UwpSubBlock: From 1eeaf7dee67e5158852bc5a18879424bc89e7c57 Mon Sep 17 00:00:00 2001 From: Martin Grottenthaler <9715799+mgrottenthaler@users.noreply.github.com> Date: Fri, 8 Aug 2025 12:10:56 +0200 Subject: [PATCH 3/3] improve entry type detection --- pylnk3.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/pylnk3.py b/pylnk3.py index 163f721..a3567a8 100644 --- a/pylnk3.py +++ b/pylnk3.py @@ -1803,10 +1803,25 @@ def for_file( elements = [RootEntry(ROOT_MY_COMPUTER), DriveEntry(levels[0])] for level in levels[1:]: - # set TYPE_FOLDER by default, unless it's the last entry (which is the file) - entry_type = TYPE_FOLDER - if level == levels[-1]: - entry_type = TYPE_FILE + entry_type = None + # check if entry exists in file system + if os.path.exists(level): + # check if entry is dir + if os.path.isdir(level): + entry_type = TYPE_FOLDER + elif os.path.isfile(level): + entry_type = TYPE_FILE + else: + raise RuntimeError(f"Unknown file system entry type for path: {level}") + else: + # path does not exist (creating from linux or different system) + # set TYPE_FOLDER by default, unless it's the last entry (which is the file) + # not possible to create links to folders + if level == levels[-1]: + entry_type = TYPE_FILE + else: + entry_type = TYPE_FOLDER + segment = PathSegmentEntry.create_for_path(level, entry_type) elements.append(segment) lnk.shell_item_id_list = LinkTargetIDList()