path-manipulation

Safe version of Path.Combine

I have a rootPath that I trust and a relativePath that I don't. I want to combine them in such a way that I can be sure that the result is under rootPath and that the user can't use .. to get back past the starting point. I do want the relative path to allow things like: hello\..\world == world ...

Code review: Determining whether a folder exists, given the full file path?

With a function being passed a full path to a file, such as C:\someFolder\anotherFolder\someXML.xml, determine whether the folder exists. Is there a smarter/better/more elegant way of doing this? Here is my implementation: Private Function FolderExists(ByVal fullPath As String) As Boolean Dim folders() As String = fullPath.Split("...

Python os.path.join on Windows

I am trying to learn python and am making a program that will output a script. I want to use os.path.join, but am pretty confused. According to the docs if I say: os.path.join('c:', 'sourcedir') I get "C:sourcedir". According to the docs, this is normal, right? But when I use the copytree command, Python will output it the desired...

how to get only the lastname of the directory, in python

Hi, guys, I am using wxpython and python to develop a gui. If I use the wx.dirdialog to get the directory like this: /folderA/folderB/folderC/folderD/ how can I get string "folderD"? Thanks in advance. ...

What is the correct way to join multiple path components into a single complete path in emacs lisp?

Suppose I have variables dir and file containing strings representing a directory and a filename, respectively . What is the proper way in emacs lisp to join them into a full path to the file? For example, if dir is "/usr/bin" and file is "ls", then I want "/usr/bin/ls". But if instead dir is "/usr/bin/", I still want the same thing, wi...