473,398 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Adding a char inside path string

Hi,

I get path strings from a DB like:

\\serverName\C:\FolderName1\FolderName2\example.ex e

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.
ServerName is not fixed length. It could be any chars length.

Thank you,
hj

Aug 16 '06 #1
21 2271
"Hitesh" wrote:
I get path strings from a DB like:

\\serverName\C:\FolderName1\FolderName2\example.ex e

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.
ServerName is not fixed length. It could be any chars length.
upath = path.replace("C:", "C$")

</F>

Aug 16 '06 #2

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:\FolderName1\FolderName2\example4 .exe',)]

I tried this:
for i in rows:
row = str(i)
path = row.replace("C:" , "c$")
print path

I am getting path something like

('\\serverName\c$:\FolderName1\FolderName2\example .exe',)

How on the earth I can remove those paranthesis?

ty
hj

Fredrik Lundh wrote:
"Hitesh" wrote:
I get path strings from a DB like:

\\serverName\C:\FolderName1\FolderName2\example.ex e

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.
ServerName is not fixed length. It could be any chars length.

upath = path.replace("C:", "C$")

</F>
Aug 16 '06 #3
In <11**********************@m73g2000cwd.googlegroups .com>, 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',),
('\\serverName\C:\FolderName1\FolderName2\example4 .exe',)]

I tried this:
for i in rows:
row = str(i)
path = row.replace("C:" , "c$")
print path

I am getting path something like

('\\serverName\c$:\FolderName1\FolderName2\example .exe',)

How on the earth I can remove those paranthesis?
Well, don't convert the tuple to a string but get the string out of the
tuple instead.

for row in rows:
path = row[0].replace('C:', 'C$')
print path

Ciao,
Marc 'BlackJack' Rintsch
Aug 16 '06 #4
On 16/08/06, Dennis Lee Bieber <wl*****@ix.netcom.comwrote:
On 16 Aug 2006 09:00:57 -0700, "Hitesh" <hi*******@gmail.comdeclaimed
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:\FolderName1\FolderName2\example. exe',),
('\\serverName\C:\FolderName1\FolderName2\example2 .exe',),
('\\serverName\C:\FolderName1\FolderName2\example3 .exe',),
('\\serverName\C:\FolderName1\FolderName2\example4 .exe',)]

I tried this:
for i in rows:
row = str(i)
path = row.replace("C:" , "c$")
print path

I am getting path something like

('\\serverName\c$:\FolderName1\FolderName2\example .exe',)

How on the earth I can remove those paranthesis?
By accessing the contents of the tuple, not the tuple itself
>rows = [('\\serverName\C:\FolderName1\FolderName2\example. exe',),
.... ('\\serverName\C:\FolderName1\FolderName2\example2 .exe',),
.... ('\\serverName\C:\FolderName1\FolderName2\example3 .exe',),
.... ('\\serverName\C:\FolderName1\FolderName2\example4 .exe',)]
>rows
[('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple.exe',),
('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple2.exe',),
('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple3.exe',),
('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple4.exe',)]
>modRows = [itm[0].replace("C:", "C$") for itm in rows]
modRows
['\\serverName\\C$\\FolderName1\\FolderName2\\examp le.exe',
'\\serverName\\C$\\FolderName1\\FolderName2\\examp le2.exe',
'\\serverName\\C$\\FolderName1\\FolderName2\\examp le3.exe',
'\\serverName\\C$\\FolderName1\\FolderName2\\examp le4.exe']
>>
Try

modRows = ['\\'+itm[0].replace(":", "$") for itm in rows]

It will work with any drive letter and makes an allowance for the
first escape character.
>>modRows
['\\\\serverName\\C$\\FolderName1\\FolderName2\\exa mple.exe',
'\\\\serverName\\C$\\FolderName1\\FolderName2\\exa mple2.exe',
.....etc

for r in modRows:
print r

\\serverName\C$\FolderName1\FolderName2\example.ex e
\\serverName\C$\FolderName1\FolderName2\example2.e xe
.......etc
:)
Aug 16 '06 #5

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, Dennis Lee Bieber <wl*****@ix.netcom.comwrote:
On 16 Aug 2006 09:00:57 -0700, "Hitesh" <hi*******@gmail.comdeclaimed
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:\FolderName1\FolderName2\example. exe',),
('\\serverName\C:\FolderName1\FolderName2\example2 .exe',),
('\\serverName\C:\FolderName1\FolderName2\example3 .exe',),
('\\serverName\C:\FolderName1\FolderName2\example4 .exe',)]
>
I tried this:
for i in rows:
row = str(i)
path = row.replace("C:" , "c$")
print path
>
I am getting path something like
>
('\\serverName\c$:\FolderName1\FolderName2\example .exe',)
>
How on the earth I can remove those paranthesis?
>
By accessing the contents of the tuple, not the tuple itself
>>rows = [('\\serverName\C:\FolderName1\FolderName2\example. exe',),
.... ('\\serverName\C:\FolderName1\FolderName2\example2 .exe',),
.... ('\\serverName\C:\FolderName1\FolderName2\example3 .exe',),
.... ('\\serverName\C:\FolderName1\FolderName2\example4 .exe',)]
>>rows
[('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple.exe',),
('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple2.exe',),
('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple3.exe',),
('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple4.exe',)]
>>modRows = [itm[0].replace("C:", "C$") for itm in rows]
>>modRows
['\\serverName\\C$\\FolderName1\\FolderName2\\examp le.exe',
'\\serverName\\C$\\FolderName1\\FolderName2\\examp le2.exe',
'\\serverName\\C$\\FolderName1\\FolderName2\\examp le3.exe',
'\\serverName\\C$\\FolderName1\\FolderName2\\examp le4.exe']
>>>

Try

modRows = ['\\'+itm[0].replace(":", "$") for itm in rows]

It will work with any drive letter and makes an allowance for the
first escape character.
>modRows
['\\\\serverName\\C$\\FolderName1\\FolderName2\\exa mple.exe',
'\\\\serverName\\C$\\FolderName1\\FolderName2\\exa mple2.exe',
....etc

for r in modRows:
print r

\\serverName\C$\FolderName1\FolderName2\example.ex e
\\serverName\C$\FolderName1\FolderName2\example2.e xe
......etc
:)
Aug 16 '06 #6
On 16 Aug 2006 10:30:26 -0700, Hitesh <hi*******@gmail.comwrote:
>
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 the character following it.

Try this
>>print "c:\server\test"
then try
>>print "c:\\server\\test"
If you need \ in a string, you should use a pair of them for safety, see

http://docs.python.org/ref/strings.html

and http://pyfaq.infogami.com/windows-index (the comments section)

HTH :)
Aug 16 '06 #7

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.e xe' -u ABC -g XYZ
abcdef

Now those padded chars are not constant all the time. It can be
anything.
Only common denometer in each string that comes with those padded chars
is that it is after .exe and then there is space and then 99% of the
time it is -u and then there can be anything, I meant its dynemic after
that.

so I am using string1.find(".exe") and could retrive the index but
don't know how to get rid any garbase after index + 4

hj
Dennis Lee Bieber wrote:
On 16 Aug 2006 09:00:57 -0700, "Hitesh" <hi*******@gmail.comdeclaimed
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:\FolderName1\FolderName2\example. exe',),
('\\serverName\C:\FolderName1\FolderName2\example2 .exe',),
('\\serverName\C:\FolderName1\FolderName2\example3 .exe',),
('\\serverName\C:\FolderName1\FolderName2\example4 .exe',)]

I tried this:
for i in rows:
row = str(i)
path = row.replace("C:" , "c$")
print path

I am getting path something like

('\\serverName\c$:\FolderName1\FolderName2\example .exe',)

How on the earth I can remove those paranthesis?
By accessing the contents of the tuple, not the tuple itself
>rows = [('\\serverName\C:\FolderName1\FolderName2\example. exe',),
... ('\\serverName\C:\FolderName1\FolderName2\example2 .exe',),
... ('\\serverName\C:\FolderName1\FolderName2\example3 .exe',),
... ('\\serverName\C:\FolderName1\FolderName2\example4 .exe',)]
>rows
[('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple.exe',),
('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple2.exe',),
('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple3.exe',),
('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple4.exe',)]
>modRows = [itm[0].replace("C:", "C$") for itm in rows]
modRows
['\\serverName\\C$\\FolderName1\\FolderName2\\examp le.exe',
'\\serverName\\C$\\FolderName1\\FolderName2\\examp le2.exe',
'\\serverName\\C$\\FolderName1\\FolderName2\\examp le3.exe',
'\\serverName\\C$\\FolderName1\\FolderName2\\examp le4.exe']
>>
--
Wulfraed Dennis Lee Bieber KD6MOG
wl*****@ix.netcom.com wu******@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@bestiaria.com)
HTTP://www.bestiaria.com/
Aug 16 '06 #8
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.e xe'

Larry Bates

Hitesh wrote:
>

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.e xe' -u ABC -g XYZ
abcdef

Now those padded chars are not constant all the time. It can be
anything.
Only common denometer in each string that comes with those padded chars
is that it is after .exe and then there is space and then 99% of the
time it is -u and then there can be anything, I meant its dynemic after
that.

so I am using string1.find(".exe") and could retrive the index but
don't know how to get rid any garbase after index + 4

hj
Dennis Lee Bieber wrote:
>On 16 Aug 2006 09:00:57 -0700, "Hitesh" <hi*******@gmail.comdeclaimed
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:\FolderName1\FolderName2\example. exe',),
('\\serverName\C:\FolderName1\FolderName2\exampl e2.exe',),
('\\serverName\C:\FolderName1\FolderName2\exampl e3.exe',),
('\\serverName\C:\FolderName1\FolderName2\exampl e4.exe',)]

I tried this:
for i in rows:
row = str(i)
path = row.replace("C:" , "c$")
print path

I am getting path something like

('\\serverName\c$:\FolderName1\FolderName2\examp le.exe',)

How on the earth I can remove those paranthesis?
By accessing the contents of the tuple, not the tuple itself
>>>>rows = [('\\serverName\C:\FolderName1\FolderName2\example. exe',),
... ('\\serverName\C:\FolderName1\FolderName2\example2 .exe',),
... ('\\serverName\C:\FolderName1\FolderName2\example3 .exe',),
... ('\\serverName\C:\FolderName1\FolderName2\example4 .exe',)]
>>>>rows
[('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple.exe',),
('\\serverName\\C:\\FolderName1\\FolderName2\\exa mple2.exe',),
('\\serverName\\C:\\FolderName1\\FolderName2\\exa mple3.exe',),
('\\serverName\\C:\\FolderName1\\FolderName2\\exa mple4.exe',)]
>>>>modRows = [itm[0].replace("C:", "C$") for itm in rows]
modRows
['\\serverName\\C$\\FolderName1\\FolderName2\\examp le.exe',
'\\serverName\\C$\\FolderName1\\FolderName2\\exam ple2.exe',
'\\serverName\\C$\\FolderName1\\FolderName2\\exam ple3.exe',
'\\serverName\\C$\\FolderName1\\FolderName2\\exam ple4.exe']
--
Wulfraed Dennis Lee Bieber KD6MOG
wl*****@ix.netcom.com wu******@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@bestiaria.com)
HTTP://www.bestiaria.com/
Aug 16 '06 #9

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='\\serverName\C:\FolderName1\FolderName2\example .exe' -u ABC -g XYZ
p=s.split(" ", 1)[0]
print p

'\\serverName\C:\FolderName1\FolderName2\example.e xe'

Larry Bates

Hitesh wrote:


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.e xe' -u ABC -g XYZ
abcdef

Now those padded chars are not constant all the time. It can be
anything.
Only common denometer in each string that comes with those padded chars
is that it is after .exe and then there is space and then 99% of the
time it is -u and then there can be anything, I meant its dynemic after
that.

so I am using string1.find(".exe") and could retrive the index but
don't know how to get rid any garbase after index + 4

hj
Dennis Lee Bieber wrote:
On 16 Aug 2006 09:00:57 -0700, "Hitesh" <hi*******@gmail.comdeclaimed
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:\FolderName1\FolderName2\example. exe',),
('\\serverName\C:\FolderName1\FolderName2\example 2.exe',),
('\\serverName\C:\FolderName1\FolderName2\example 3.exe',),
('\\serverName\C:\FolderName1\FolderName2\example 4.exe',)]

I tried this:
for i in rows:
row = str(i)
path = row.replace("C:" , "c$")
print path

I am getting path something like

('\\serverName\c$:\FolderName1\FolderName2\exampl e.exe',)

How on the earth I can remove those paranthesis?

By accessing the contents of the tuple, not the tuple itself

rows = [('\\serverName\C:\FolderName1\FolderName2\example. exe',),
... ('\\serverName\C:\FolderName1\FolderName2\example2 .exe',),
... ('\\serverName\C:\FolderName1\FolderName2\example3 .exe',),
... ('\\serverName\C:\FolderName1\FolderName2\example4 .exe',)]
rows
[('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple.exe',),
('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple2.exe',),
('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple3.exe',),
('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple4.exe',)]
modRows = [itm[0].replace("C:", "C$") for itm in rows]
modRows
['\\serverName\\C$\\FolderName1\\FolderName2\\examp le.exe',
'\\serverName\\C$\\FolderName1\\FolderName2\\examp le2.exe',
'\\serverName\\C$\\FolderName1\\FolderName2\\examp le3.exe',
'\\serverName\\C$\\FolderName1\\FolderName2\\examp le4.exe']
--
Wulfraed Dennis Lee Bieber KD6MOG
wl*****@ix.netcom.com wu******@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@bestiaria.com)
HTTP://www.bestiaria.com/
Aug 16 '06 #10
>>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\example .exe' -u ABC -g XYZ
p=s.split(" ", 1)[0]
print p

'\\serverName\C:\FolderName1\FolderName2\example.e xe'

Larry Bates

Hitesh wrote:


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.e xe' -u ABC -g XYZ
abcdef

Now those padded chars are not constant all the time. It can be
anything.
Only common denometer in each string that comes with those padded chars
is that it is after .exe and then there is space and then 99% of the
time it is -u and then there can be anything, I meant its dynemic after
that.

so I am using string1.find(".exe") and could retrive the index but
don't know how to get rid any garbase after index + 4

hj
Dennis Lee Bieber wrote:
On 16 Aug 2006 09:00:57 -0700, "Hitesh" <hi*******@gmail.comdeclaimed
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:\FolderName1\FolderName2\example. exe',),
('\\serverName\C:\FolderName1\FolderName2\example 2.exe',),
('\\serverName\C:\FolderName1\FolderName2\example 3.exe',),
('\\serverName\C:\FolderName1\FolderName2\example 4.exe',)]

I tried this:
for i in rows:
row = str(i)
path = row.replace("C:" , "c$")
print path

I am getting path something like

('\\serverName\c$:\FolderName1\FolderName2\exampl e.exe',)

How on the earth I can remove those paranthesis?

By accessing the contents of the tuple, not the tuple itself

rows = [('\\serverName\C:\FolderName1\FolderName2\example. exe',),
... ('\\serverName\C:\FolderName1\FolderName2\example2 .exe',),
... ('\\serverName\C:\FolderName1\FolderName2\example3 .exe',),
... ('\\serverName\C:\FolderName1\FolderName2\example4 .exe',)]
rows
[('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple.exe',),
('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple2.exe',),
('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple3.exe',),
('\\serverName\\C:\\FolderName1\\FolderName2\\exam ple4.exe',)]
modRows = [itm[0].replace("C:", "C$") for itm in rows]
modRows
['\\serverName\\C$\\FolderName1\\FolderName2\\examp le.exe',
'\\serverName\\C$\\FolderName1\\FolderName2\\examp le2.exe',
'\\serverName\\C$\\FolderName1\\FolderName2\\examp le3.exe',
'\\serverName\\C$\\FolderName1\\FolderName2\\examp le4.exe']
--
Wulfraed Dennis Lee Bieber KD6MOG
wl*****@ix.netcom.com wu******@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@bestiaria.com)
HTTP://www.bestiaria.com/
Aug 16 '06 #11
On 2006-08-16, Hitesh <hi*******@gmail.comwrote:
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
isn't allowed at the end of a path.

Then delete the stuff that isn't allowed.

--
Grant Edwards grante Yow! Hello? Enema
at Bondage? I'm calling
visi.com because I want to be happy,
I guess...
Aug 16 '06 #12

anything after .exe should be truncated (or deleted).
Grant Edwards wrote:
On 2006-08-16, Hitesh <hi*******@gmail.comwrote:
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
isn't allowed at the end of a path.

Then delete the stuff that isn't allowed.

--
Grant Edwards grante Yow! Hello? Enema
at Bondage? I'm calling
visi.com because I want to be happy,
I guess...
Aug 16 '06 #13

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 should be truncated (or deleted).
Grant Edwards wrote:
On 2006-08-16, Hitesh <hi*******@gmail.comwrote:
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
isn't allowed at the end of a path.

Then delete the stuff that isn't allowed.

--
Grant Edwards grante Yow! Hello? Enema
at Bondage? I'm calling
visi.com because I want to be happy,
I guess...
Aug 16 '06 #14
On 2006-08-16, Hitesh <hi*******@gmail.comwrote:
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!
Aug 16 '06 #15
On 2006-08-16, Hitesh <hi*******@gmail.comwrote:
>
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)
That will fail if the ".exe" isn't found.

--
Grant Edwards grante Yow! Does someone from
at PEORIA have a SHORTER
visi.com ATTENTION span than me?
Aug 16 '06 #16

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 <hi*******@gmail.comwrote:
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!
Aug 16 '06 #17


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 <hi*******@gmail.comwrote:
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!
Aug 16 '06 #18

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:
Sindex = Sindex + 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 <hi*******@gmail.comwrote:
>
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!
Aug 16 '06 #19
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<clip here>"')
>>edited_path_name = Editor (tricky_path_name)
>>print edited_path_name # See what it did
\serverName\C$:\exe files\example.exe<clip here>u ABC -g DEF
>>path_name = edited_path_name.split ('<clip here>')[0]
>>print path_name
\serverName\C$:\exe files\example.exe # There you go
Note 1: As long as 'print edited_path_name' doesn't look right, change the substitution definitions that make your Editor. Maybe
there should be no colon after the '$'. So change ''C:=C$:' to ''C:=C$'. Should your Editor ever fail to handle a path name having
an unexpected format, add another substitution definition to also accommodate the new format.

Note 2: '<clip here>' is a self-documenting split mark. You'd pick a more convenient one.

Note 3: If the path name ends with 'exe' it works all the same. The edited path name will not have '<clip here>'. So the split will
be a list containing one element instead of two. In either case the edited path name is at index 0.

Note 4: Get SE at: http://cheeseshop.python.org/pypi/SE/2.2%20beta

Regards

Frederic
----- Original Message -----
From: "Hitesh" <hi*******@gmail.com>
Newsgroups: comp.lang.python
To: <py*********@python.org>
Sent: Wednesday, August 16, 2006 4:15 PM
Subject: Adding a char inside path string

Hi,

I get path strings from a DB like:

\\serverName\C:\FolderName1\FolderName2\example.ex e

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.
ServerName is not fixed length. It could be any chars length.

Thank you,
hj

--
http://mail.python.org/mailman/listinfo/python-list
Aug 17 '06 #20
On 17/08/06, Sybren Stuvel <sy*******@yourthirdtower.com.imaginationwrote:
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 it wouldn't open, because it was an
invalid .COM file...
It is possible on XP. I just created this structure

C:\Documents and Settings\TW\Desktop\test\test.com\test.exe\test
space\data\data.txt

:)
Aug 17 '06 #21
On 2006-08-17, Sybren Stuvel <sy*******@YOURthirdtower.com.imaginationwrote:
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 "www.something.com" and then
it wouldn't open, because it was an invalid .COM file...
Works fine for me. I just created both directories and plain
text files named something.exe and www.something.com and both
worked fine under WinMe and WinXP.

--
Grant Edwards grante Yow! Well, I'm on the
at right planet---everyone
visi.com looks like me!!!
Aug 17 '06 #22

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: hokiegal99 | last post by:
I've written a small script (with much help from this list) that searches through a directory for files without a PC filename extension like .doc .xls and then adds them. The reason for writing the...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
7
by: brian_harris | last post by:
I have a string object that I need to convert into an unmanged char * to be used by several unmnaged 3rd party functions. I have tried to use: (Marshal::StringToHGlobalAuto (Profname)) This would...
0
by: bonita | last post by:
If I add the code for user to download the file (e.g. if(File.Exists(FILE_NAME)){......}), the ASP.NET will give the following timeout error: Timeout expired. The timeout period elapsed prior to...
4
by: thoseion | last post by:
Hi, I am trying to get a program working whereby directory and file names are read into a list. I have been given the original list structure - it appears that the directory names should be added...
0
by: buntyindia | last post by:
Hi, I have a very strange problem with my application. I have developed it using Struts. I have a TextBox With Some fixed value in it and on Submit iam passing it to another page. <html:form...
0
by: NatsoumiMaya | last post by:
hi ppl, i have a code to write in C where i have to implement the mkdir, rm, rmdir and touch functions using double linked lists...im haveing trouble with it...here is what i have so far: #ifndef...
1
by: Odd B Andersen | last post by:
I am trying to create a function that adds 1 to the value in a hexadecimalcolumn. This function I want to use inside an SQL PL procedure. I have a table with a column with char(16) for bit data....
13
by: Hongyu | last post by:
Hi, I have a datetime char string returned from ctime_r, and it is in the format like ""Wed Jun 30 21:49:08 1993\n\0", which has 26 chars including the last terminate char '\0', and i would...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.