Guest User

[Python] Path shortener

a guest
Jul 14th, 2017
145
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def cut_path(path):
  2.     ''' This function takes a path and outputs the path cut with the ... after the
  3.     the first folder after the first character and completes the name with the filename or the last folder
  4.    Example:
  5.    C:/Users/Mauro/Desktop/DenoiseAvg/DenoiseAverage/test_cut_path.py
  6.    C:/Users/.../test_cut_path.py
  7.     '''      
  8.     endidx = 5
  9.     char = path[endidx]    
  10.     while char != '/' and endidx < len(path):
  11.         endidx += 1
  12.         char = path[endidx]
  13.        
  14.     inpath = path[:endidx + 1 ]
  15.    
  16.     rpath = path[::-1]    
  17.     idx = 1  
  18.     char = rpath[idx]    
  19.     while char != "/" and idx < len(rpath):
  20.         idx += 1
  21.         char = rpath[idx]
  22.  
  23.     endpath = path[len(path) - idx - 1 : ]
  24.    
  25.     outpath = inpath + "..." + endpath
  26.     return outpath
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×