Questions tagged [path-manipulation]

31 questions
382
votes
10 answers

How to get only the last part of a path in Python?

In python, suppose I have a path like this: /folderA/folderB/folderC/folderD/ How can I get just the folderD part?
pepero
  • 7,095
  • 7
  • 41
  • 72
305
votes
10 answers

Given a filesystem path, is there a shorter way to extract the filename without its extension?

I program in WPF C#. I have e.g. the following path: C:\Program Files\hello.txt and I want to extract hello from it. The path is a string retrieved from a database. Currently I'm using the following code to split the path by '\' and then split…
KMC
  • 19,548
  • 58
  • 164
  • 253
122
votes
14 answers

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…
Frank E.
  • 1,235
  • 2
  • 10
  • 5
68
votes
8 answers

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…
Ryan C. Thompson
  • 40,856
  • 28
  • 97
  • 159
19
votes
12 answers

How to fix "Path Manipulation Vulnerability" in some Java Code?

The below simple java code getting Fortify Path Manipulation error. Please help me to resolve this. I am struggling from long time. public class Test { public static void main(String[] args) { File file=new File(args[0]); } }
mohan
  • 235
  • 1
  • 2
  • 3
8
votes
1 answer

Standard (or free) POSIX path manipulation C library

Is there any standard (or widely used) simple POSIX path manipulation library for C (path join, filename stripping, etc.) ? Actually, because I'm mostly working under Windows, I currently use 'shlwapi' path functions. Is there any equivalent set of…
rotoglup
  • 5,223
  • 25
  • 37
6
votes
4 answers

Path Manipulation (security vulnerability)

A Fortify security review informed us of some path manipulation vulnerabilities. Most have been obvious and easy fixes, but I don't understand how to fix the following one. string[] wsdlFiles = System.IO.Directory.GetFiles(wsdlPath,…
Induster
  • 733
  • 1
  • 6
  • 15
4
votes
3 answers

How can I find the potential source environment variable for a partial path in PowerShell?

I want to write a function that converts regular path to path that includes environment variables: For example: C:\Windows\SomePath convert to: %Windir%\SomePath How would I do that and is this possible? Here is what I'm trying to do, but problem…
3
votes
2 answers

Long- and Multi-format Path Manipulation Library?

Is there any path open-source manipulation library which supports all of the following? Unrestricted path lengths (i.e. the only restriction should be from the range of size_t, not arbitrary limitations like 256 characters) Basic manipulations like…
user541686
  • 205,094
  • 128
  • 528
  • 886
3
votes
3 answers

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…
BCS
  • 75,627
  • 68
  • 187
  • 294
3
votes
1 answer

How to correct Path Manipulation error given by fortify?

I need to read the properties file kept in user_home folder. PropsFile = System.getProperty("user.home") + System.getProperty("file.separator")+ "x.properties"; Fortify is giving path manipulation error in this line. The number of correct values…
Vishesh
  • 41
  • 1
  • 1
  • 5
3
votes
2 answers

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…
Mark
  • 6,123
  • 13
  • 41
  • 52
2
votes
0 answers

Python Handle Fortify Path Manipulation

I am trying to run fortify analyzer on my python code and I am trying to read a file created by my kubernetes server but I am being flagged as Path Manipulation.. What can I do to handle this Critical level in my python code? namespace =…
Mark Estrada
  • 9,013
  • 37
  • 119
  • 186
2
votes
1 answer

How can I manipulate Windows paths from a Linux app and vice versa in .NET Core?

I'm building a data transfer tool that may be deployed to either a Windows or Linux Docker container that must instruct SQL Server to take a database snapshot. Additionally, SQL Server may be on either Windows or Linux and I need to specify where…
2
votes
1 answer

How to to resolve issue Fortify path manipulation

The following code always shows path manipulation problem. How to resolve it ? string pathMaterData = ServerName + "\\MaterData\\"; if (!Directory.Exists(Path.Combine(ServerName, "\\MaterData\\"))) { …
Jamebond Tkk
  • 73
  • 1
  • 6
1
2 3