Remove unwanted path name from %path% variable via batch

This removes the substring C:\Program Files (x86)\Git\bin; from the PATH string and re-assigns: set PATH=%PATH:C:\Program Files (x86)\Git\bin;=% You might use this to see the change: echo %PATH:C:\Program Files (x86)\Git\bin;=% | tr ; \n Note: be exact on the substring. It’s case-sensitive and slash-sensitive. If you need to make it a persistent change use setx instead … Read more

Comparing two paths in python

Use os.path.normpath to convert c:/fold1/fold2 to c:\fold1\fold2: >>> path1 = “c:/fold1/fold2” >>> list_of_paths = [“c:\\fold1\\fold2″,”c:\\temp\\temp123”] >>> os.path.normpath(path1) ‘c:\\fold1\\fold2′ >>> os.path.normpath(path1) in list_of_paths True >>> os.path.normpath(path1) in (os.path.normpath(p) for p in list_of_paths) True os.path.normpath(path1) in map(os.path.normpath, list_of_paths) also works, but it will build a list with entire path items even though there’s match in the middle. … Read more

Pathlib vs. os.path.join in Python

pathlib is the more modern way since Python 3.4. The documentation for pathlib says that “For low-level path manipulation on strings, you can also use the os.path module.” It doesn’t make much difference for joining paths, but other path commands are more convenient with pathlib compared to os.path. For example, to get the “stem” (filename … Read more

Setting up enviroment variables in Windows 10 to use java and javac

Just set the path variable to JDK bin in environment variables. Variable Name : PATH Variable Value : C:\Program Files\Java\jdk1.8.0_31\bin But the best practice is to set JAVA_HOME and PATH as follow. Variable Name : JAVA_HOME Variable Value : C:\Program Files\Java\jdk1.8.0_31 Variable Name : PATH Variable Value : %JAVA_HOME%\bin

What is the best way to combine a path and a filename in C#/.NET?

If you want “bad” filenames to generate an error: if (Path.GetFileName(fileName) != fileName) { throw new Exception(“‘fileName’ is invalid!”); } string combined = Path.Combine(dir, fileName); Or, if you just want to silently correct “bad” filenames without throwing an exception: string combined = Path.Combine(dir, Path.GetFileName(fileName));