Remove filename from a URL/Path in java

Consider using org.apache.commons.io.FilenameUtils You can extract the base path, file name, extensions etc with any flavor of file separator: String url = “C:\\windows\\system32\\cmd.exe”; String baseUrl = FilenameUtils.getPath(url); String myFile = FilenameUtils.getBaseName(url) + “.” + FilenameUtils.getExtension(url); System.out.println(baseUrl); System.out.println(myFile); Gives, windows\system32\ cmd.exe With url; String url = “C:/windows/system32/cmd.exe”; It would give; windows/system32/ cmd.exe

Unable to locate files with long names on Windows with Python

Use the 8.3 fallback to avoid the long pathname, browsing in Win7 explorer this seems to be what windows itself does, ie every long paths has a shorter ‘true name’: >>> long_unc=”\\\\K53\\Users\\Tolan\\testing\\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\\xxxxxxxxxxxxxxxxxxxxxxxxdddddddddddddddddddddwgggggggggggggggggggggggggggggggggggxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\\esssssssssssssssssssssggggggggggggggggggggggggggggggggggggggggggggggeee” >>> os.listdir(long_unc) FileNotFoundError: [WinError 3] but you can use win32api (pywin32) to ‘build’ up a shorter version, ie short_unc=win32api.GetShortPathName(win32api.GetShortPathName(win32api.GetShortPathName(“\\\\K53\\Users\\Tolan\\testing\\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”)+”\\xxxxxxxxxxxxxxxxxxxxxxxxdddddddddddddddddddddwgggggggggggggggggggggggggggggggggggxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”) + “\\esssssssssssssssssssssggggggggggggggggggggggggggggggggggggggggggggggeee”) >>> print(short_unc) … Read more

Get filepath and filename of selected gallery image in Android

A little late to the party but here’s my code, hope this helps. public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { Uri selectedImageUri = data.getData( ); String picturePath = getPath( getActivity( ).getApplicationContext( ), selectedImageUri ); Log.d(“Picture Path”, picturePath); } } public static String getPath( Context context, Uri uri ) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)