My software outputs these two types of output:
-rwx------ Administrators/Domain Users 456220672 0% 2018-04-16 16:04:40 E:\\_WiE10-18.0.100-77.iso
-rwxrwx--- Administrators/unknown 6677 0% 2018-04-17 01:33:23 E:\\program files\\cluster groups\\sql server (mssqlserver)\\logs\\progress-MOD-1523883344023-3001-Windows.log
I would like to get the file names from both outputs:
E:\\_WiE10-18.0.100-77.iso
, for the first oneE:\\program files\\cluster groups\\sql server (mssqlserver)\\logs\\progress-MOD-1523883344023-3001-Windows.log
, for the second one
If i use something like the code below, it won't work if the second parameter has spaces in it. It works if there aren't any spaces in the Domain Username.
for item in outputs:
outputs.extend(item.split())
for item2 in [' '.join(outputs[6:])]:
new_list.append(item2)
How can I get all the parameters individually, including the filenames?
You could use a regular expression like
If regex is an option:
Output:
Pattern explained:
The pattern
r"^.*?\d\d:\d\d:\d\d (.*)"
looks for linestart'^'
+ as less anythings as possible'.*?'
+ the time-stamp'\d\d:\d\d:\d\d '
followed by a space and captures all behind it till end of line into a group.It uses the
re.MULTILINE
flag for that.Edit:
Capturing the individual things needs some more capturing groups:
Output:
Aside from using regex, you can try something similar to this.
It looks for the first occurrence of
':\\'
and gets the drive letter before the substring (i.e.':\\'
) and the full file path after the substring.EDIT
Patrick Artner's answer is better and completely answers OP's question compared to this answer. This only encompasses capturing the file path. I am leaving this answer here should anyone find it useful.