-1

I'm adding in some logic to my code to check if a file has been created. I don't have the actual file name since it's procedurally generated when the code runs. However, it has a distinct file type '.nzt'

The easiest way I can think to do this is using os.path.exists(), but I don't know what to put as the path.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • 2
    What have you tried so far? – JRiggles Aug 17 '23 at 19:37
  • 1
    If you don't know the file name, `exists` isn't going to help. – Scott Hunter Aug 17 '23 at 19:38
  • Look at https://stackoverflow.com/q/3207219/535275 – Scott Hunter Aug 17 '23 at 19:41
  • 3
    Do you know what directory it will be in? Will it be the only `.nzt` file in that directory? If yes to both you can use `glob.glob('/path/to/directory/*.nzt')` to check if there are any files with that type. – Barmar Aug 17 '23 at 19:42
  • You can use `glob` to find all files in a given directory that end in .nzt. That won't tell you whether its an old file. If your code starts before this .nzt file appears, you can read the existing ones then compare after it does appear. If you have control over where this file is written, you could create a one-time-use directory. – tdelaney Aug 17 '23 at 19:44

0 Answers0