path-manipulation

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

北城以北 提交于 2021-01-27 07:12:43
问题 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 is, I need to check the string for all possible variables, is there some more automatic way? such that -replace operator wont be needed function Format-Path { param ( [parameter(Mandatory = $true)] [string] $FilePath ) if (![System.String]:

How to correct Path Manipulation error given by fortify?

烂漫一生 提交于 2019-12-09 13:46:26
问题 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 is large so blacklisting is the only way possible. So to avoid it i changed the code as below. String propsFile = null; StringBuffer sb = new StringBuffer(); String xProperties = "x.properties"; String userHome = System.getProperty("user.home"); // *

How to fix “Path Manipulation Vulnerability” in some Java Code?

别等时光非礼了梦想. 提交于 2019-12-07 01:27:46
问题 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]); } } 回答1: Looking at the OWASP page for Path Manipulation, it says An attacker can specify a path used in an operation on the filesystem You are opening a file as defined by a user-given input. Your code is almost a perfect example of the vulnerability! Either Don't use the

How to correct Path Manipulation error given by fortify?

北城余情 提交于 2019-12-03 21:04:17
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 is large so blacklisting is the only way possible. So to avoid it i changed the code as below. String propsFile = null; StringBuffer sb = new StringBuffer(); String xProperties = "x.properties"; String userHome = System.getProperty("user.home"); // * if(userHome.contains("..\\")) userHome = userHome.replace("..\\", ""); if(userHome.contains("../"))

Standard (or free) POSIX path manipulation C library

本小妞迷上赌 提交于 2019-12-03 13:06:04
问题 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 functions available for POSIX paths? 回答1: path join - snprintf() filename stripping - dirname() etc. - basename(), realpath(), readlink(), glob(), fnmatch()... 来源: https://stackoverflow.com/questions/8900980/standard-or-free-posix-path-manipulation

Standard (or free) POSIX path manipulation C library

孤者浪人 提交于 2019-12-03 03:22:09
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 functions available for POSIX paths? path join - snprintf() filename stripping - dirname() etc. - basename(), realpath(), readlink(), glob(), fnmatch()... 来源: https://stackoverflow.com/questions/8900980/standard-or-free-posix-path-manipulation-c-library

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

早过忘川 提交于 2019-11-27 10:30:31
In Python, suppose I have a path like this: /folderA/folderB/folderC/folderD/ How can I get just the folderD part? Use os.path.normpath , then os.path.basename : >>> os.path.basename(os.path.normpath('/folderA/folderB/folderC/folderD/')) 'folderD' The first strips off any trailing slashes, the second gives you the last part of the path. Using only basename gives everything after the last slash, which in this case is '' . You could do >>> import os >>> os.path.basename('/folderA/folderB/folderC/folderD') UPDATE1: This approach works in case you give it /folderA/folderB/folderC/folderD/xx.py.

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

谁说胖子不能爱 提交于 2019-11-26 15:09:06
问题 In Python, suppose I have a path like this: /folderA/folderB/folderC/folderD/ How can I get just the folderD part? 回答1: Use os.path.normpath, then os.path.basename: >>> os.path.basename(os.path.normpath('/folderA/folderB/folderC/folderD/')) 'folderD' The first strips off any trailing slashes, the second gives you the last part of the path. Using only basename gives everything after the last slash, which in this case is '' . 回答2: You could do >>> import os >>> os.path.basename('/folderA

Python os.path.join on Windows

被刻印的时光 ゝ 提交于 2019-11-26 12:15:12
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 way, for example: import shutil src = os.path.join('c:', 'src') dst = os.path.join('c:', 'dst') shutil.copytree(src, dst) Here is the error code I get: WindowsError: [Error 3] The system cannot find the path specified: 'C:src/*.*' If I wrap the os.path.join with os

Python os.path.join on Windows

£可爱£侵袭症+ 提交于 2019-11-26 03:35:44
问题 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 way, for example: import shutil src = os.path.join(\'c:\', \'src\') dst = os.path.join(\'c:\', \'dst\') shutil.copytree(src, dst) Here is the error code I