Adding a char inside path string
Hitesh
hitesh287 at gmail.com
Wed Aug 16 17:07:35 EDT 2006
How about this:
def TruncateString(s, Tindex):
return string.ljust(s,Tindex){:Tindex]
s = '\\serverName\\C:\\Folder Name1\\FolderName2\\example.exe -u ABC -g
XYZ'
try:
Sindex = s.find(".exe")
if Sindex > 0:
Sindex = Tindex + 4
s1 = TruncateString(s, Sindex)
except:
pass
hj
Hitesh wrote:
> I post a crappy solution but I can add few more stuff to make it fail
> proof.
> i.e. I can search for ".exe -u"
> But if someone names folder like "folder.exe u". This script could
> fail.
> Or if in padded garbase I get ".exe u"
>
> These are two known issues I have to takcle.
>
> Thanks everyone for your help.
>
>
>
> Grant Edwards wrote:
> > On 2006-08-16, Hitesh <hitesh287 at gmail.com> wrote:
> >
> > > anything after .exe should be truncated (or deleted).
> >
> > That will fail if any directory names contain the string
> > ".exe", but if that's what you want, it's trivial enough:
> >
> > for s in ["asdfasdf.exe -u", "soemthing/else", "asdf.exe/qwerqwer/qwerqwer.exe"]:
> > print `s`,
> > i = s.find(".exe")
> > print i,
> > if i >= 0:
> > s = s[:i+4]
> > print `s`
> >
> > --
> > Grant Edwards grante Yow! Yow! It's some people
> > at inside the wall! This is
> > visi.com better than mopping!
More information about the Python-list
mailing list