subdirectory

Python – Recursive subfolder loop

Python – Recursive subfolder loop Question: I’m looking to build a dictionary based on a directory’s subfolders. Note that this isn’t an OS directory, so I can’t use the os library. The below code works, but is limited to 3 levels of subdirectories. How can I build a loop that will handle any number of …

Total answers: 1

How to import folders in python?

How to import folders in python? Question: I have 3 folders of excel data and was asked to create a Machine Learning model using that data. But the problem is that the data does not have headers. How to import all those folders of data in Python. Asked By: Sounak Sarkar || Source Answers: Python …

Total answers: 1

mp3 file name replace

mp3 file name replace Question: So my concern on a logic of a program. I have a Music folder with many mp3 files with underscores in names (MC_-_Best_track.mp3). So I want to scan this folder and replace all underscores with whitespaces. I want to write it myself first but I need a kickstart for that) …

Total answers: 1

Rename files in subdirectories with the root directory name in an zipfile

Rename files in subdirectories with the root directory name in an zipfile Question: I have the following directory structure within my zip file: myzip.zip – directory 1 – subdirectory 1 – imageA.jpg – imageB.jpg – directory 2 – subdirectory 2 – imageA.jpg – imageB.jpg And my goal is to rename the .jpg files to main …

Total answers: 2

How to create a Python nested dictionary based on a FTP tree of folders

How to create a Python nested dictionary based on a FTP tree of folders Question: I’m trying to create a dictionary based on a tree of folders located on a FTP server (see image below): The result I’m looking for is : A primary dictionnary that have secondary dictionnaries (as keys) with some lists (as …

Total answers: 1

How to copy a folder into an existing folder using python

How to copy a folder into an existing folder using python Question: I am new to python, and am currently trying to copy a folder ‘foo’ (potentially with some files/folders inside) into another existing folder ‘bar’. After this, there should be a new path created that should look something like this "…bar/foo/*". By copying ‘foo’ …

Total answers: 2

Get name (not full path) of subdirectories in python

Get name (not full path) of subdirectories in python Question: There are many posts on Stack Overflow that explain how to list all the subdirectories in a directory. However, all of these answers allow one to get the full path of each subdirectory, instead of just the name of the subdirectory. I have the following …

Total answers: 4

Including ipynb files in sphinx index.rst when they are located in a subdirectory

Including ipynb files in sphinx index.rst when they are located in a subdirectory Question: I am stuck with pythons sphinx. My directory tree looks like this: | – project_root | | – importable_project | | | – importable_module.py | | | – another_importable_module.py | | | – Tutorials | | | | – tutorial1.ipynb | …

Total answers: 2

Multiple directories and/or subdirectories in IPython Notebook session?

Multiple directories and/or subdirectories in IPython Notebook session? Question: The IPython documentation pages suggest that opening several different sessions of IPython notebook is the only way to interact with saved notebooks in different directories or subdirectories, but this is not explicitly confirmed anywhere. I am facing a situation where I might need to interact with …

Total answers: 2

Import module from subfolder

Import module from subfolder Question: I want to import subfolders as modules. Therefore every subfolder contains a __init__.py. My folder structure is like this: src main.py dirFoo __init__.py foofactory.py dirFoo1 __init__.py foo1.py dirFoo2 __init__.py foo2.py In my main script I import from dirFoo.foofactory import FooFactory In this factory file I include the sub modules: from …

Total answers: 5