Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get file description
#1
Quote:I have the small code here, as it stands right now it works perfectly

What I'm trying to do is to get it to stop looking at program = r'\ccsetup551.exe'
I'm trying to get it to look in

with open(r'Program_Recovery2_Selection.txt', 'r') as file:
file4 = file.read().replace('\n', "")
file.close()

for the file name but every time I replace program with file4
it tells me it's unknown

except is only if the file does not have a description
it will display an unknown

As you can see I am using ccleaner.exe as an example
so how do I get this script to look in the Program_Recovery2_Selection.txt
and add it to the path

import win32api

file4 = ''


def get_file_description(windows_exe):
    global file4
    try:
        language, codepage = win32api.GetFileVersionInfo(windows_exe, '\\VarFileInfo\\Translation')[0]
        stringfileinfo = u'\\StringFileInfo\\%04X%04X\\%s' % (language, codepage, "FileDescription")
        description = win32api.GetFileVersionInfo(windows_exe, stringfileinfo)

        with open(r'Program_Recovery2_Selection.txt', 'r') as file:   <----- look in here
            file4 = file.read().replace('\n', "")
            file.close()

    except (Exception,):  # adding (Exception,) seem to work I don't know why
        description = "unknown"  # if the program doesn't have a description

    return description


path = r'\\MyCloudPR4100\Programs\Specialty tools'
program = r'\ccsetup551.exe'  # ccsetup551.exe     <--- not here
print(get_file_description(path + program))
Reply
#2
This seems to work:

from pathlib import Path

# py -3.12 -m pip install pywin32
import pywintypes
from win32api import GetFileVersionInfo


def get_description(exe: str | Path) -> str:
    exe = str(exe)
    
    try:
        language, codepage = GetFileVersionInfo(exe, '\\VarFileInfo\\Translation')[0]
    except pywintypes.error:
        return "Unkown"
    
    return GetFileVersionInfo(exe, fr'\StringFileInfo\{language:04X}{codepage:04X}\FileDescription')



for exe in Path(r"C:\Windows\System32").glob("*.exe"):
    print(exe.name, get_description(exe), sep=": ")
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
(Nov-23-2023, 01:16 PM)DeaD_EyE Wrote: This seems to work:

from pathlib import Path

# py -3.12 -m pip install pywin32
import pywintypes
from win32api import GetFileVersionInfo


def get_description(exe: str | Path) -> str:
    exe = str(exe)
    
    try:
        language, codepage = GetFileVersionInfo(exe, '\\VarFileInfo\\Translation')[0]
    except pywintypes.error:
        return "Unkown"
    
    return GetFileVersionInfo(exe, fr'\StringFileInfo\{language:04X}{codepage:04X}\FileDescription')



for exe in Path(r"C:\Windows\System32").glob("*.exe"):
    print(exe.name, get_description(exe), sep=": ")
Quote:I actually try something similar to that
but I wanted to look in the text file

I actually just a little while ago figured out what the problem was
and I solve my problem
thank you everyone for helping out
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is the 'meta description' html tag not translated? Melcu54 2 983 Oct-15-2022, 10:55 PM
Last Post: Larz60+
  What should i do, for this code to work -> description hamad 2 1,467 Nov-18-2021, 01:22 PM
Last Post: ghoul
  Classes in general description Python_User 2 1,926 Sep-01-2020, 05:30 PM
Last Post: Python_User

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020