Python Forum
Adding regedit value to glob.glob
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding regedit value to glob.glob
#1
How do I add a value from regedit for example, location of a file to glob.glob function?

I wanted to use glob.glob to read a particular folder for files with a particular extension for example .exe. The particular folder to read must be the location stored in regedit. So, How do I get it done?

from winreg import *
import glob, os

key = OpenKey(HKEY_CURRENT_USER, r'SOFTWARE\Ubisoft', 0, KEY_ALL_ACCESS)
val = QueryValueEx(key, "ac_syndicate_exe")
print(val)

path = str(val)
for filename in glob.iglob('path/**/*.cs', recursive=True ):
   print(filename)
Also there's a small issue;

In regedit the path is stored with \\ whereas in normal drive path its stored with \ ...example:


E:\\Games (Stored)\\Ubisoft\\ac3.exe -> Path stored in Regedit
E:\Games (Stored)\Ubisoft\ac3.exe -> Drive Path
Reply
#2
Here you go. I rewrote your code just a little bit. But it should do what you wanted now:

from winreg import *
import glob, os
 
key = OpenKey(HKEY_CURRENT_USER, r'SOFTWARE\Ubisoft', 0, KEY_ALL_ACCESS)
# Get the path and make it more workable. Note the escaped characters
path = QueryValueEx(key, "ac_syndicate_exe")[0].replace("\\\\", "/")

# Trim off the actual executable file name
path = path[0:path.rfind("/")]
print(path)

for filename in glob.iglob(path + "/path_to_files/*.cs", recursive=True):
    print(filename)
Reply
#3
(Apr-25-2017, 08:34 AM)AlterBlitz Wrote: Also there's a small issue;

In regedit the path is stored with \\ whereas in normal drive path its stored with \
Are they? Or is that just what you see when you print the path? Backslashes are normally escaped when printing to the console, fyi:

>>> path = r"E:\some\dir\file.txt"
>>> path
'E:\\some\\dir\\file.txt'
>>> print(path)
E:\some\dir\file.txt
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  |SOLVED] Glob JPGs, read EXIF, update file timestamp? Winfried 5 2,481 Oct-21-2021, 03:29 AM
Last Post: buran
  [SOLVED] Input parameter: Single file or glob? Winfried 0 1,586 Sep-10-2021, 11:54 AM
Last Post: Winfried
  q re glob.iglob iterator and close jimr 2 2,236 Aug-23-2021, 10:14 PM
Last Post: perfringo
  Listing files with glob. MathCommander 9 4,958 Oct-26-2020, 02:04 AM
Last Post: MathCommander
  Adding markers to Folium map only adding last element. tantony 0 2,125 Oct-16-2019, 03:28 PM
Last Post: tantony
  Version of glob for that Supports Windows Wildcards? Reverend_Jim 5 5,662 Jun-18-2019, 06:31 PM
Last Post: Reverend_Jim
  nested for loops glob devenuro 3 5,124 Sep-20-2018, 09:54 PM
Last Post: ODIS
  Glob and automating help Thunberd 0 2,378 Jun-13-2018, 04:42 PM
Last Post: Thunberd
  Issues with running regedit command from python gohanzdad 10 9,915 May-16-2017, 04:28 PM
Last Post: gohanzdad
  glob for dir listing bluefrog 5 4,601 Mar-07-2017, 05:46 PM
Last Post: bluefrog

Forum Jump:

User Panel Messages

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