os.walk

Build JSON object directory tree using Python os.walk

Build JSON object directory tree using Python os.walk Question: So I’m just hitting a mental roadblock on solving this problem and none of the other questions I have looked at have really captured my particular use-case. One was close but I couldn’t quite figure out how to tailor it specifically. Basically, I have a script …

Total answers: 2

Find leaf folders that aren't hidden folders

Find leaf folders that aren't hidden folders Question: I have a folder structure with some epubs and json files in the down-most folders (not counting the .ts folders). I’m exporting tags from the json files to tagspaces, by creating a .ts folder with some other json files. I’ve already processed part of the files and …

Total answers: 1

Print number of occurrences of any items in a list in paths

Print number of occurrences of any items in a list in paths Question: I am using os.walk to identify paths in a generic source directory (SRC) that contain any strings in my_list: SRC = ‘/User/dir_1/’ my_list = ["dog", "cat", "mouse", "bird"] for dirpath, dirnames, filenames in os.walk(SRC): for folders in dirnames: for x in my_list: …

Total answers: 1

os.walk isn't showing all the files in the given path

os.walk isn't showing all the files in the given path Question: I’m trying to make my own backup program but to do so I need to be able to give a directory and be able to get every file that is somewhere deep down in subdirectories to be able to copy them. I tried making …

Total answers: 1

How can I ignore or remove ".ipynb_checkpoints" in colab?

How can I ignore or remove ".ipynb_checkpoints" in colab? Question: My code in tf.keras is given below. I want to retrieve a file(Xscale.npy) in each sub_directory(component_0, component_1) of model_cnn folder. root_dir = ‘/content/drive/My Drive/DeepCID/model_cnn’ i=0 for (root, dirs, files) in os.walk(root_dir): for d in dirs: print(dirs) os.chdir(os.path.join(root, d)) print(os.getcwd()) datafile3 = ‘./Xscale.npy’ Xscale = np.load(datafile3) …

Total answers: 4

os.walk is returning a generator object. What am I doing wrong?

os.walk is returning a generator object. What am I doing wrong? Question: According to the documentation, os.walk returns a tuple with root, dirs and files in a given path. When I call os.walk I get the following: >>> import os >>> os.listdir(‘.’) [‘Makefile’, ‘Pipfile’, ‘setup.py’, ‘.gitignore’, ‘README.rst’, ‘.git’, ‘Pipfile.lock’, ‘.idea’, ‘src’] >>> root, dir, files …

Total answers: 1

word count PDF files when walking directory

word count PDF files when walking directory Question: Hello Stackoverflow community! I’m trying to build a Python program that will walk a directory (and all sub-directories) and do a accumulated word count total on all .html, .txt, and .pdf files. When reading a .pdf file it requires a little something extra (PdfFileReader) to parse the …

Total answers: 1