On 07/11/2018 15:56, Asad wrote: > Hi All, > > I tired seems its not working as required : > > from os.path import dirname, join > > testdir = dirname("/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log")
Note that this will set testdir to /a/b/c/d/test/test_2814__2018_10_05_12_12_45 But you want the dir above that. The easiest way (if this is always the case) is to just use dirname() again: testdir = dirname(testdir) Which should result in: /a/b/c/d/test You could of course do it in one line as myPath = "/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log" testdir = dirname( dirname(myPath) ) Which is nicer than my original suggestion of using chdir and relative paths :-) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor