Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • So from the the originally posted code, I would not have to import anything as I already have from os import path included, correct? And as that code applies to me, would it be like parent_dir = lambda thisDir: split(thisDir)[0] if isdir(thisDir) else split(dirname(thisDir))[0] then newDirectory = path.join(parent_dir + "\Extracted Items", file + " - Extracted Items")? Commented Aug 11, 2011 at 17:13
  • Ah, so I should use parent_dir = lambda x: split(x)[0] if isdir(x) else dirname(x) as my definition of parent directory is the immediate parent directy of the folder I am currently working in? Commented Aug 11, 2011 at 17:16
  • Yes, if you only use dirname(x) you'll recieve the folder the file x is in. And yes, path is already included. If you do not import the functions directly, you can access them using the point notation. parent_dir = lambda x: path.split(x)[0] if path.isdir(x) else path.dirname(x). In your last code snipped, you need to call the function to activate it and give it the path to work on: newDirectory = path.join(parent_dir(currentDirectory), "Extracted Items", file + "- Extracted Items"). Commented Aug 11, 2011 at 18:11
  • Note that path.join does automatically add \ between the arguments passed to it, so you can replace path.join(thisDir + "\Extracted Items", file, ..) with path.join(thisDir, "Extracted Items", file, ..) Commented Aug 11, 2011 at 18:13