Re: Adding a char inside path string

2006-08-17 Thread Grant Edwards
On 2006-08-17, Sybren Stuvel <[EMAIL PROTECTED]> wrote: > Dennis Lee Bieber enlightened us with: >> What happens when you get a pathname that looks like: >> >> \\who\cares\common.exe\program.exe > > Is that possible on Windows? Sure. Why wouldn't it be? > At one point, I named a directory "

Re: Adding a char inside path string

2006-08-17 Thread Tim Williams
On 17/08/06, Sybren Stuvel <[EMAIL PROTECTED]> wrote: > Dennis Lee Bieber enlightened us with: > > What happens when you get a pathname that looks like: > > > > \\who\cares\common.exe\program.exe > > Is that possible on Windows? At one point, I named a directory > "www.something.com" and then

Re: Adding a char inside path string

2006-08-16 Thread Anthra Norell
Hitesh, You might want to try this: >>> tricky_path_name = '\\serverName\\C:\\exe files\\example.exe -u ABC -g DEF' >>> import SE >>> Editor = SE.SE ('C:=C$: "exe -=exe"') >>> edited_path_name = Editor (tricky_path_name) >>> print edited_path_name# See what it did \serverName\C$:\exe fil

Re: Adding a char inside path string

2006-08-16 Thread Hitesh
There was a typo. I corrected it. Hitesh wrote: > 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: >

Re: Adding a char inside path string

2006-08-16 Thread Hitesh
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:

Re: Adding a char inside path string

2006-08-16 Thread Hitesh
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.

Re: Adding a char inside path string

2006-08-16 Thread Grant Edwards
On 2006-08-16, Hitesh <[EMAIL PROTECTED]> wrote: > > Here is a mediocare solution. > > def TruncateString(s, Tindex): > return string.ljust(s,Tindex){:Tindex] > > s = '\\serverName\\C:\\Folder Name1\\FolderName2\\example.exe -u ABC -g > XYZ' > Sindex = s.find(".exe") > Sindex = Tindex +4 > s1 =

Re: Adding a char inside path string

2006-08-16 Thread Grant Edwards
On 2006-08-16, Hitesh <[EMAIL PROTECTED]> 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.

Re: Adding a char inside path string

2006-08-16 Thread Hitesh
Here is a mediocare solution. def TruncateString(s, Tindex): return string.ljust(s,Tindex){:Tindex] s = '\\serverName\\C:\\Folder Name1\\FolderName2\\example.exe -u ABC -g XYZ' Sindex = s.find(".exe") Sindex = Tindex +4 s1 = TruncateString(s, Sindex) Hitesh wrote: > anything after .exe sh

Re: Adding a char inside path string

2006-08-16 Thread Hitesh
anything after .exe should be truncated (or deleted). Grant Edwards wrote: > On 2006-08-16, Hitesh <[EMAIL PROTECTED]> wrote: > > > That might work but what if I get (in future) a path name where > > foldername (and in windows it is very common, someone might name a > > folder something like "Sc

Re: Adding a char inside path string

2006-08-16 Thread Grant Edwards
On 2006-08-16, Hitesh <[EMAIL PROTECTED]> wrote: > That might work but what if I get (in future) a path name where > foldername (and in windows it is very common, someone might name a > folder something like "Screw You") with space? You must come up with a rigorous specification for what is and i

Re: Adding a char inside path string

2006-08-16 Thread Hitesh
>>> s = '\\serverName\C:\Folder Name1\FolderName2\example.exe -u ABC -g XYZ' >>> p = s.split(" ", 1)[0] >>> p '\\serverName\\C:\\Folder' hj Larry Bates wrote: > Sounds like you can split the string on a space and throw > away the right side: > > s='\\serverName\C:\FolderName1\FolderName2\exampl

Re: Adding a char inside path string

2006-08-16 Thread Hitesh
That might work but what if I get (in future) a path name where foldername (and in windows it is very common, someone might name a folder something like "Screw You") with space? Larry Bates wrote: > Sounds like you can split the string on a space and throw > away the right side: > > s='\\server

Re: Adding a char inside path string

2006-08-16 Thread Larry Bates
Sounds like you can split the string on a space and throw away the right side: s='\\serverName\C:\FolderName1\FolderName2\example.exe' -u ABC -g XYZ p=s.split(" ", 1)[0] print p '\\serverName\C:\FolderName1\FolderName2\example.exe' Larry Bates Hitesh wrote: > > > Hi, > > Everything is workin

Re: Adding a char inside path string

2006-08-16 Thread Hitesh
Hi, Everything is working fine and dandy but I ran across another issue here. Some of the path comes with some extra chars padded at the end. i.e. '\\serverName\C:\FolderName1\FolderName2\example.exe' -u ABC -g XYZ abcdef Now those padded chars are not constant all the time. It can be anythin

Re: Adding a char inside path string

2006-08-16 Thread Tim Williams
On 16 Aug 2006 10:30:26 -0700, Hitesh <[EMAIL PROTECTED]> wrote: > > Thank you all it worked!. > > Tim, > > > modRows = ['\\'+itm[0].replace(":", "$") for itm in rows] > > What are those two forward slashes for? Hi Hitesh, \ is an escape character, it can give unexpected results depending on t

Re: Adding a char inside path string

2006-08-16 Thread Hitesh
Thank you all it worked!. Tim, > modRows = ['\\'+itm[0].replace(":", "$") for itm in rows] What are those two forward slashes for? I had to remove them otherwise I was getting output like '\\' inside list or if I print I was getting like \\\ Thanks, hj Tim Williams wrote: > On 16/08/06,

Re: Adding a char inside path string

2006-08-16 Thread Tim Williams
On 16/08/06, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On 16 Aug 2006 09:00:57 -0700, "Hitesh" <[EMAIL PROTECTED]> declaimed > the following in comp.lang.python: > > > > > Thank you Fredrik. That works for a string. > > But I am getting list of tuples from DB. > > > > rows = [('\\serverName\C:

Re: Adding a char inside path string

2006-08-16 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Hitesh wrote: > That works for a string. > But I am getting list of tuples from DB. > > rows = [('\\serverName\C:\FolderName1\FolderName2\example.exe',), > ('\\serverName\C:\FolderName1\FolderName2\example2.exe',), > ('\\serverName\C:\FolderName1\FolderName2\example3.exe',

Re: Adding a char inside path string

2006-08-16 Thread Hitesh
Thank you Fredrik. That works for a string. But I am getting list of tuples from DB. rows = [('\\serverName\C:\FolderName1\FolderName2\example.exe',), ('\\serverName\C:\FolderName1\FolderName2\example2.exe',), ('\\serverName\C:\FolderName1\FolderName2\example3.exe',), ('\\serverName\C:\FolderName

Re: Adding a char inside path string

2006-08-16 Thread Fredrik Lundh
"Hitesh" wrote: > I get path strings from a DB like: > > \\serverName\C:\FolderName1\FolderName2\example.exe > > I am writing a script that can give me access to that exe file. > But problem is that string is not universal path, I need to add C$. > Any idea how I can add $ char in that string. > S