0

This is the code I have written:
import os
s=""
pr=""
x=""
i=0
for (p,d,f) in os.walk('d:\\12'):
i+=1
if i <= 3:
pr=str(p)
s=str(d)
s=s.strip("[]")
e=(len(s.strip("\'\'")))
#print(s,e)
x=str(f).strip("[]")
y=pr+"\\"+x.strip("\'\'")
print(y)

This is it's output: d:\12\bvzcasdas\14\hello.txt What I want as the result is the drive letter & the immediate sub-directory (i.e 12) should be skipped in the final result.

Abhi
  • 192
  • 1
  • 4
  • 17
H3M3
  • 1
  • 1

1 Answers1

0

You can use cut command to get output. If i get question right this should work:

echo "D:\1\2\3\4\5\6\7\8\hello.txt" | cut -d "\" -f 4-

This will cut the input with delimiter "\" and print from 4th column to last column. Output will be:

3\4\5\6\7\8\hello.txt

EDIT: (After new contains in question )

You can add following line:
os.system("echo %s | cut -d '\' -f 3- "%y);

just adjust column value to set from where to start displaying.

Abhi
  • 192
  • 1
  • 4
  • 17
  • Thanks... but the one I have given above is just an example... The code has to be independent of the file names... – H3M3 Jul 08 '13 at 07:09
  • You can use any thing over there Take path in any variable and echo $variable to echo path. Then cut for column number – Abhi Jul 08 '13 at 07:22
  • Thanks again... But i'm getting – H3M3 Jul 08 '13 at 11:08
  • 'cut' is not recognized as an internal or external command, operable program or batch file. – H3M3 Jul 08 '13 at 11:09
  • What do i have to import to use the cut command in Eclipse...? with PyDev plugin – H3M3 Jul 10 '13 at 05:20
  • I don't have much idea about eclipse or on windows itself. may be (not sure) this will help to use cut (or similler command) on windows "http://stackoverflow.com/questions/4441827/windows-command-for-cutting-columns-from-a-text" – Abhi Jul 10 '13 at 05:51
  • if it is the solution you want then accept it as correct so it may help others – Abhi Jul 19 '13 at 08:22