So, I want to create a simple script to create directories based upon the file names contained within a certain folder.
My method looks like this:
def make_new_folders(filenames, destination):
"""
Take a list of presets and create new directories using mkdir
"""
for filename in filenames:
path = '"%s/%s/"' % (destination, filename)
subprocess.call(["mkdir", path])
For some reason I can’t get the command to work.
If I pass in a file named “Test Folder”, i get an error such as:
mkdir: "/Users/soundteam/Desktop/PlayGround/Test Folder: No such file or directory
Printing the ‘path’ variable results in:
“/Users/soundteam/Desktop/PlayGround/Test Folder/”
Can anyone point me in the right direction?
You don’t need the double quotes.
subprocesspasses the parameters directly to the process, so you don’t need to prepare them for parsing by a shell. You also don’t need the trailing slash, and should use os.path.join to combine path components:EDIT: You should accept @Fabian’s answer, which explains that you don’t need subprocess at all (I knew that).