After correcting the backslash problem you still get no output so I have tested your code. I have no inetsrv config so I have tested it on powershell.exe.config, also in a System32 subdirectory. Your code ran ok and produced output.
The only reasons I can come up with for not generating output are:
1-no python adminstrator rights for a System32 subdirectory
2-non existing file
3-the hidden directory you mentioned
4-the file is empty
The first 3 reasons should produce an error/exception if not allowed.
The test program:
import os
# finalFilePath = r"C:\Windows\System32\inetsrv\config\applicationHost.config"
finalFilePaths = [
r"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.config",
r"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe - empty.config",
r"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe - non existing.config",
r"C:\test\hidden\powershell.exe.config",
r"C:\test\hidden\powershell.exe - empty.config",
r"C:\test\hidden\powershell.exe - non existing.config",
r"C:\test\non hidden\powershell.exe.config",
r"C:\test\non hidden\powershell.exe - empty.config",
r"C:\test\non hidden\powershell.exe - non existing.config",
]
for finalFilePath in finalFilePaths:
print(f'START: {finalFilePath}')
if not os.path.exists(finalFilePath):
print(f'ERROR: file not found {finalFilePath}')
try:
with open(finalFilePath) as wsfinalfile_document:
openFinalFile = wsfinalfile_document.read()
print(openFinalFile)
except Exception as e:
print(f'EXCEPTION: {str(e)}')
print('END -----------------------')
Testing shows that only reason 2 generates an exception. The other are allowed. The only way the test program generates no output/exception is if the file is empty.
START: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.config
<configuration>
...
</configuration>
END -----------------------
START: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe - empty.config
END -----------------------
START: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe - non existing.config
ERROR: file not found C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe - non existing.config
EXCEPTION: [Errno 2] No such file or directory: 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe - non existing.config'
END -----------------------
START: C:\test\hidden\powershell.exe.config
<configuration>
...
</configuration>
END -----------------------
START: C:\test\hidden\powershell.exe - empty.config
END -----------------------
START: C:\test\hidden\powershell.exe - non existing.config
ERROR: file not found C:\test\hidden\powershell.exe - non existing.config
EXCEPTION: [Errno 2] No such file or directory: 'C:\\test\\hidden\\powershell.exe - non existing.config'
END -----------------------
START: C:\test\non hidden\powershell.exe.config
<configuration>
...
</configuration>
END -----------------------
START: C:\test\non hidden\powershell.exe - empty.config
END -----------------------
START: C:\test\non hidden\powershell.exe - non existing.config
ERROR: file not found C:\test\non hidden\powershell.exe - non existing.config
EXCEPTION: [Errno 2] No such file or directory: 'C:\\test\\non hidden\\powershell.exe - non existing.config'
END -----------------------
Process finished with exit code 0