Python 3 code
Here's a simple Python 3 script (md23.py
) which shows that the directory isn't where you think it is.
#!/usr/bin/env python3
import os
new_folder = 'Zarazogic acid A'
print("0:", os.listdir('.'))
os.mkdir(new_folder)
print("1:", os.listdir('.'))
os.chdir(new_folder)
print("2:", os.listdir('.'))
os.chdir('..')
print("3:", os.listdir('.'))
os.rmdir(new_folder)
print("4:", os.listdir('.'))
It's not beautiful, but it works with Python 3 — you'd have to change the printing to make it work with Python 2.
When the script is in an otherwise empty directory, the output is:
0: ['md23.py']
1: ['md23.py', 'Zarazogic acid A']
2: []
3: ['md23.py', 'Zarazogic acid A']
4: ['md23.py']
This shows that the directory could be created, listed, changed to, that the new directory was empty, that it still existed when changing back up a directory level, and that it could be removed.
You should be able to take this, place it beside your current script, and run it, and it should succeed. If the Zarazogic acid A
directory already exists, it will fail. For example, if I create the directory before running the script, I get this output:
$ mkdir 'Zarazogic acid A'
$ python3 md23.py
0: ['md23.py', 'Zarazogic acid A']
Traceback (most recent call last):
File "md23.py", line 8, in <module>
os.mkdir(new_folder)
FileExistsError: [Errno 17] File exists: 'Zarazogic acid A'
$
Python 2 code
A variant script, md29.py
, with directory names printed too:
#!/usr/bin/env python2.7
import os
new_folder = 'Zarazogic acid A'
print "0:", os.getcwd(), os.listdir('.')
os.mkdir(new_folder)
print "1:", os.getcwd(), os.listdir('.')
os.chdir(new_folder)
print "2:", os.getcwd(), os.listdir('.')
os.chdir('..')
print "3:", os.getcwd(), os.listdir('.')
os.rmdir(new_folder)
print "4:", os.getcwd(), os.listdir('.')
Example run:
0: /Users/jleffler/soq/junk ['md23.py', 'md29.py']
1: /Users/jleffler/soq/junk ['md23.py', 'md29.py', 'Zarazogic acid A']
2: /Users/jleffler/soq/junk/Zarazogic acid A []
3: /Users/jleffler/soq/junk ['md23.py', 'md29.py', 'Zarazogic acid A']
4: /Users/jleffler/soq/junk ['md23.py', 'md29.py']