Re: [Tutor] Regex for Filesystem path (Asad)

2018-11-08 Thread Peter Otten
Albert-Jan Roskam wrote: > I was thinking it would also be possible to do (in Windows): > import os.path > os.path.sep = '/' > os.path.normpath('c:\\beeh/foo\\bar/baz') > > But alas, this still creates normalized windows-style paths. If your input data has only forward slashes you can keep it th

Re: [Tutor] Regex for Filesystem path (Asad)

2018-11-08 Thread Albert-Jan Roskam
From: Tutor on behalf of Alan Gauld via Tutor Sent: Thursday, November 8, 2018 10:49 AM To: tutor@python.org Subject: Re: [Tutor] Regex for Filesystem path (Asad) On 08/11/2018 02:55, Asad wrote: > Why is it putting \ this breaks the unix path it should be: > > /a/b

Re: [Tutor] Regex for Filesystem path (Asad)

2018-11-08 Thread Alan Gauld via Tutor
On 08/11/2018 02:55, Asad wrote: > Why is it putting \ this breaks the unix path it should be: > > /a/b/c/d/test/28163133/22326541 ===> for unix platform logs > > \a\b\c\d\test\28163133\22326541 ===> for windows platform logs os.path.join uses the separator that is correct for your OS. Sinc

Re: [Tutor] Regex for Filesystem path (Asad)

2018-11-08 Thread Asad
uld > To: tutor@python.org > Cc: > Bcc: > Date: Wed, 7 Nov 2018 19:21:58 + > Subject: Re: [Tutor] Regex for Filesystem path (Asad) > On 07/11/2018 15:56, Asad wrote: > > Hi All, > > > > I tired seems its not working as required : > > > &

Re: [Tutor] Regex for Filesystem path (Asad)

2018-11-07 Thread Alan Gauld via Tutor
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_

Re: [Tutor] Regex for Filesystem path (Asad)

2018-11-07 Thread Asad
23456/789 Instead i need the script to go to the location : /a/b/c/d/test/123456/789 Please advice . Thanks, > -- Forwarded message -- > From: Cameron Simpson > To: tutor@python.org > Cc: > Bcc: > Date: Wed, 7 Nov 2018 06:47:33 +1100 > Subject: R

Re: [Tutor] Regex for Filesystem path

2018-11-06 Thread Sarfraaz Ahmed
Hello, There are specific operating system, path related modules in Python for handling these scenarios. You could try looking at os.path module. On Tue, Nov 6, 2018 at 11:16 PM Asad wrote: > Hi all , > > Can you provide some advice and code for the following problem : > > I have a log

Re: [Tutor] Regex for Filesystem path

2018-11-06 Thread Alan Gauld via Tutor
On 06/11/2018 19:47, Cameron Simpson wrote: > It is better to just construct the required path. Chdir there requires a > chdir back, and chdir affects all the relative paths your programme may > be using. > > I'd use os.path.dirname to get '/a/b/c/d/test' and then just append to > it with os.p

Re: [Tutor] Regex for Filesystem path

2018-11-06 Thread Cameron Simpson
On 06Nov2018 18:10, Alan Gauld wrote: >On 06/11/2018 13:13, Asad wrote: > >> Can you provide some advice and code for the following problem : > >The first thing is to go read the documentation for the os.path module. >It is designed for reliable path manipulation. > >> /a/b/c/d/test/test_2

Re: [Tutor] Regex for Filesystem path

2018-11-06 Thread Mats Wichmann
>>4) look for the latest file in the directory /a/b/c/d/test/123456/789 > > Slightly more complex, you need the creation timestamp. > You can find that with os.path.getctime() (or several > other options, eg os.stat) here's a trick you might be able to make use of: somelist = generate-lis

Re: [Tutor] Regex for Filesystem path

2018-11-06 Thread Alan Gauld via Tutor
On 06/11/2018 13:13, Asad wrote: > Can you provide some advice and code for the following problem : The first thing is to go read the documentation for the os.path module. It is designed for reliable path manipulation. > /a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log > > f3 = ope