'Python: How to read multiple .NBT files and export to JSON?
I am a newbie when it comes to programming and i'm looking for a way to iterate through a directory filled with .NBT files and export them to JSON. I know i can loop thorugh a directory using os.listdir, but i have trouble reading the files one by one and deciding what steps to take in order to get it to a JSON format.
The actual assignment is to loop through a bunch of .NBT files to see which Minecraft crate is faced towards with direction.
This is what i have now:
import python_nbt.nbt as nbt
import os
for file in os.listdir("Directory to nbt files"):
if file.endswith(".nbt"):
filename = nbt.read_from_nbt_file(file)
From here i get a FileNotFoundError saying there is no such file or directory.
What am i doing wrong? And what must be done to continue?
Solution 1:[1]
you didn't specified the folder the file is in:
do nbt.read_from_nbt_file('Directory to nbt files' + '\\' + file)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | ???? ?????? |