Write NON-HIDDEN file to APPDATA with Python3 in Windows 10

  appdata, hidden-files, python, python-3.x, windows

What specific syntax must be used in order for a Python3 program to successfully write a visible (NOT hidden) file to the APPDATA directory in Windows 10?

CURRENT FAILED ATTEMPT:

The following code writes a HIDDEN file to APPDATA, which is NOT what we want.

print(os.getenv('APPDATA'))
someFileName = os.path.join( os.getenv('APPDATA'), "terraform.rc")
print("someFileName is: ", someFileName)
print("About to write someFileName. ")
try: 
  with open(someFileName, 'w') as f:
    f.write('some stuffn')
except (Exception) as e:
  print(e)

The following code reads the HIDDEN file that was just written above:

print("About to read the someFileName we just wrote.  ")
with open(someFileName, 'r') as lines:
  for line in lines:
    print(line)

But the problem is that other tools running in the system are NOT able to find the same file because it is HIDDEN.

Since we are not able to control how the other tools function, we must provide a NON-HIDDEN file. When we manually put a NON-HIDDEN file in the APPDATA folder, the other tools work. But this needs to work when the file is written automatically by Python. And currently the problem is that the Python code above creates a hidden file that the other tools cannot see.

Source: Windows Questions

LEAVE A COMMENT