1. Doubling \\ in file names

Hi All

I think that I am having trouble because of needing to double back 
slashes in a file name for various GUI commands such as extractIcon. If 
I have a file name with single back slashes then is there some function 
that will make them all double or am I doing something daft?

What is the rule on what things treat "\" in text in this way (i.e. as a 
special escape character)?  Is it always the case in all text strings, 
or do some just have normal single "\" in file names?

I am using create( PictureButton, ... and want to put an extractIcon(f) 
command directly in as a parameter for the picture icon and it seems the 
reason for failure is that f has single back slashes.

I am going to have a working program soon!  smile  smile  smile

Ray

new topic     » topic index » view message » categorize

2. Re: Doubling \\ in file names

On Wed, 18 Jun 2003 17:58:09 +1200 (06/18/03 15:58:09)
, Ray Tomes <rtomes at ihug.co.nz> wrote:

>
>
> Hi All
>
> I think that I am having trouble because of needing to double back 
> slashes in a file name for various GUI commands such as extractIcon. If I 
> have a file name with single back slashes then is there some function 
> that will make them all double or am I doing something daft?
>
> What is the rule on what things treat "\" in text in this way (i.e. as a 
> special escape character)?  Is it always the case in all text strings, or 
> do some just have normal single "\" in file names?
>
> I am using create( PictureButton, ... and want to put an extractIcon(f) 
> command directly in as a parameter for the picture icon and it seems the 
> reason for failure is that f has single back slashes.
>

Hi Ray,
this has nothing to do with file names, that's just a red-herring. Inside 
string literals, the backslash character '\' has a special meaning. Certain 
two-character combinations are used to represent special characters. They 
are (from memory)...

\t	The TAB character \n	The new-line character
\\	The backslash character

This means that if you need to specify a backslash in a string you need to 
write it as a double \\.

Thus "C:\\Program Files\\My Application\\abc.dat" is converted by Euphoria 
to

C:\Program Files\My Application\abc.dat

The other combinations are useful for embedding new-lines and TABs inside 
strings.

Hope this helps.


-- 

cheers,
Derek Parnell

new topic     » goto parent     » topic index » view message » categorize

3. Re: Doubling \\ in file names

----- Original Message -----
From: "Ray Tomes" <rtomes at ihug.co.nz>
To: "EUforum" <EUforum at topica.com>
Subject: Doubling \\ in file names


>
>
> Hi All
>
> I think that I am having trouble because of needing to double back
> slashes in a file name for various GUI commands such as extractIcon. If
> I have a file name with single back slashes then is there some function
> that will make them all double or am I doing something daft?

Try the function below, it's simple, no tests for if you happened to already
have doubled backslashes.

>
> What is the rule on what things treat "\" in text in this way (i.e. as a
> special escape character)?  Is it always the case in all text strings,
> or do some just have normal single "\" in file names?

I think it's the same in all sequences, although it *may* be possible (I'm
not sure) that if you get a filename from some function like current_dir,
and then use that in some other function where a filename is expected, you
might not have to worry about double slashes?  I forget.

Dan Moyer

>
> I am using create( PictureButton, ... and want to put an extractIcon(f)
> command directly in as a parameter for the picture icon and it seems the
> reason for failure is that f has single back slashes.
>
> I am going to have a working program soon!  smile  smile  smile
>
> Ray
>
>

-- function to make double backslashes out of singles:

function DblUpBkSlshs (sequence in)
sequence temp
temp = {}

  for n = 1 to length(in) do
    temp &= in[n]
    if equal(in[n], '\\') then
       temp &= "\\"
    end if
  end for
  return temp
end function

--------------------------
-- test it:
include file.e

sequence a
a = current_dir()
puts(1, a & "\n")
a = DblUpBkSlshs(a)
puts(1, a & "\n")
a = "abc\\def\\ghijk\\"
puts(1, a & "\n")
a = DblUpBkSlshs(a)
puts(1, a)


>
>
> TOPICA - Start your own email discussion group. FREE!
>
>

new topic     » goto parent     » topic index » view message » categorize

4. Re: Doubling \\ in file names

You need to type double backslashes ONLY in source files (*.ex, *.exw),
not in anything outside it. For example if you make code like this

puts(1, "Enter a file name: ")
filename = gets(0)  -- prompt a file name
-- then user types: c:\abc\def.ext
fn = open(filename, "r")

You don't need to convert the contents of variable "filename" to
double backslashes for the open() function.

YOu need double backslashes ONLY in source files. Not the others.

I think the extractIcon() is not compatible with picturebutton, not
because of the backslash thing.
______________________________________________
R> Hi All

R> I think that I am having trouble because of needing to double back 
R> slashes in a file name for various GUI commands such as extractIcon. If 
R> I have a file name with single back slashes then is there some function 
R> that will make them all double or am I doing something daft?

R> What is the rule on what things treat "\" in text in this way (i.e. as a 
R> special escape character)?  Is it always the case in all text strings, 
R> or do some just have normal single "\" in file names?

R> I am using create( PictureButton, ... and want to put an extractIcon(f) 
R> command directly in as a parameter for the picture icon and it seems the 
R> reason for failure is that f has single back slashes.

R> I am going to have a working program soon!  smile  smile  smile

R> Ray

new topic     » goto parent     » topic index » view message » categorize

5. Re: Doubling \\ in file names

aku saya wrote:

> You need to type double backslashes ONLY in source files (*.ex, *.exw),
> not in anything outside it.

Hi Aku and others

(hides red face)

Yes, I worked this out but couldn't get back here quick enough to pull 
the string on my message back!  blink

Must have been programming too many hours lately!

Ray

new topic     » goto parent     » topic index » view message » categorize

6. Re: Doubling \\ in file names

Al,

That's a *very* clear & succinct explanation!

Dan Moyer

----- Original Message ----- 
From: "Al Getz" <Xaxo at aol.com>
To: "EUforum" <EUforum at topica.com>
Subject: RE: Doubling \\ in file names


> 
> 
> Hello again,
> 
> The only time you dont use double backslashes is when
> you type an 'include' statement that includes a path
> directory name or whatever (in a source file).
> 
> Ex:
> 
>     include c:\mydir\files\file.e
> 
> Whenever they are inclosed in double quotes you have to:
> 
> atom fn
> fn=open("C:\\dir\\file.txt","r")
> 
> Take care for now,
> Al
> 
> 
> 
> TOPICA - Start your own email discussion group. FREE!
>

new topic     » goto parent     » topic index » view message » categorize

7. Re: Doubling \\ in file names

I just always remember there are six. Straight from the Eu docs:
Special characters may be entered using a back-slash:=20

        \n        newline
        \r        carriage return
        \t        tab
        \\        backslash
        \"        double quote
        \'        single quote

Pete
(Struggling to get through some 100+ posts (possibly not all from this
list) at the mo!)

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu