User Tools

Site Tools


task_boiler

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
task_boiler [2023/05/03 16:17] admintask_boiler [2024/01/23 22:55] (current) raju
Line 4: Line 4:
 Start the first heading with "=====" Start the first heading with "====="
  
-===== find depth ===== 
-==== find depth of a file or directory ==== 
-<code> 
-import os 
-  
-def get_depth(file_or_dir_path): 
-    abs_path = os.path.abspath(os.path.expanduser(file_or_dir_path)) 
-    depth = os.path.normpath(abs_path).count(os.sep) 
-    return depth 
-</code> 
- 
-Examples: 
-<code> 
-In [2]:  
-os.path.abspath(os.path.expanduser('~')) 
-Out[2]:  
-'/home/rajulocal' 
- 
-In [3]:  
-get_depth('~') 
-Out[3]:  
-2 
- 
-In [4]:  
-get_depth('/home/rajulocal') 
-Out[4]:  
-2 
- 
-In [5]:  
-get_depth('/home/rajulocal/') 
-Out[5]:  
-2 
- 
-In [6]:  
-get_depth('/home/rajulocal/foo') 
-Out[6]:  
-3 
- 
-In [7]:  
-get_depth('/') 
-Out[7]:  
-1 
- 
-In [8]:  
-get_depth('/home') 
-Out[8]:  
-1 
-</code> 
- 
-Using Python 3.10.6, Ipython 8.6.0 
- 
-tags | get depth of a directory 
task_boiler.1683130674.txt.gz · Last modified: 2023/05/03 16:17 by admin