Python Forum
Generate a list - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Generate a list (/thread-34955.html)



Generate a list - sasitha96 - Sep-19-2021

How to generate a list of all the ‘.exe’ files available in ‘C:\Windows\system32’ directory and store them in a log file created in the C drive with the name of ‘entries_Win10.log’.


RE: Generate a list - nilamo - Sep-19-2021

What have you tried?

This is a place for helping people to learn Python, not for people to solve your problems for you. If you're not going to write code, we have nothing to help with.


RE: Generate a list - snippsat - Sep-19-2021

You should try yourself as this is a relative easy task,we do not like a task posted without any effort,then is more job description.
That's said here a start(saving to log file you should try yourself), these days pathlib is a more modern way to do it.
import pathlib

win_dir = r'C:\Windows\System32'
for file in pathlib.Path(win_dir).glob('*.exe'):
    if file.is_file():
        print(file)



RE: Generate a list - dgrunwal - Sep-20-2021

sasitha96,

The code provided works, of course you can simply capture to a file or code the file capture in Python. Or you could use DOS

C:\Windows\System32>dir *.exe >> E:\\mafiles.txt

Or run the Python code and output to a file:

C:\python3.8.5>python check.py >> EXEFILES.TXT


Best,
Dave


RE: Generate a list - sasitha96 - Sep-20-2021

(Sep-19-2021, 06:47 PM)nilamo Wrote: What have you tried?

This is a place for helping people to learn Python, not for people to solve your problems for you. If you're not going to write code, we have nothing to help with.

sorry for that Undecided


RE: Generate a list - sasitha96 - Sep-20-2021

(Sep-19-2021, 06:48 PM)snippsat Wrote: You should try yourself as this is a relative easy task,we do not like a task posted without any effort,then is more job description.
That's said here a start(saving to log file you should try yourself), these days pathlib is a more modern way to do it.
import pathlib

win_dir = r'C:\Windows\System32'
for file in pathlib.Path(win_dir).glob('*.exe'):
    if file.is_file():
        print(file)

thanks Heart