Reputation: 136
Python2.7
filenamepath is a variable I created which is the file path of a Quicktime mov. Here I am checking if a folder with the filename of the Quicktime mov (but with .folder at end of foldername) exists and if not, os.makedirs is creating one.
How would I then assign this directory path to a variable? I want to then use shutil.move to move the .mov into the .folder.
import os
if not os.path.exists(filenamepath.replace(".mov", ".folder")):
os.makedirs(filenamepath.replace(".mov", ".folder"))
Upvotes: 0
Views: 1716
Reputation: 690
Your best best is probably to assign variables to target folder names:
filenamepath = "/some/path/to/my_video.mov"
target_dir = filenamepath.replace(".mov", ".folder")
if not os.path.exists(target_dir):
os.makedirs(target_dir)
shutil.move(filenamepath, target_dir)
That would clarify the intention of the code significantly.
Upvotes: 3