tjguk / wmi

102 stars 29 forks source link

Matching Path variable in wmi.WMI().CIM_Datafile #26

Open josephlaus opened 1 year ago

josephlaus commented 1 year ago

Greetings,

I am trying to get some files by extension, drive and path, however, I cannot find out a way to get the Path variable of the files match with a string.

This will work getting all the .dat files in c drive. conn = wmi.WMI() for f in conn.CIM_Datafile(Extension='dat',Drive='c:'): print(f)

If I add a condition for Path, there is no way I could get any matching. conn = wmi.WMI() for f in conn.CIM_Datafile(Extension='dat',Drive='c:',Path='\\users\\user1\\appdata\\local\\temp\\'): print(f)

I have tried just the string, raw string and f string, double backslashes, four backslashes, nothing worked in the above code.

I could get around using Path from pathlib but I assume because it is going through each file, the time it takes is very long. conn = wmi.WMI() for f in conn.CIM_Datafile(Extension='dat',Drive='c:'): if Path(f.Path) == Path('\\users\\user1\\appdata\\local\\temp\\'): print(f)

Any suggestions welcomed.

Thanks in advance.