java - Trim Filename to be short enough -


i writing api based gui, in want full filename appear... filename long, , want trim filename leave out few folders needed. example:

c:\users\roiex\somefolder\someotherfolder\somefile.someextension

should trimmed like

c:\...\someotherfolder\somefile.someextension

i have variable filename, generated calling file.getabsolutepath(). have method, let's call toolarge(filename) start :

string filename = file.getabsolutepath(); while(toolarge(filename)){     filename = trimpath(filename); } render(filename); 

what should inside trimpath() ?

any appreciated

a proper regex replaceall() work :

public static void main(string[] args) {     string s = "c:\\asas\\users\\roiex\\somefolder\\someotherfolder\\somefile.someextension";     system.out.println(s.replaceall("(\\w+:\\\\).*?(\\\\\\w+\\\\\\w+.\\w+)$", "$1...$2"));   } 

o/p :

c:\...\someotherfolder\somefile.someextension 

the above regex selects last starting directory , last directory file name.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -