1. RENAME problem: directories with spaces?

Juergen's suggestion for using "rename" with "system" command,  
sequence myvar
myvar = "\"the old.txt\" \"the new.txt\""    -- or whatever is required
system("rename " & myvar, 2)

seems like it should have worked, but didn't; I get an error about
 "bad command format", but when I make it print out, it looks fine, except:  

the path to the file(s) includes more than one directory with SPACES in them,
which I think is the problem, and I vaguely remember that there's a "trick"
to making directories with spaces work, but I don't rember what it IS.

Is there such a trick?  (& what is it if there is)
(in the code example above, I put the path to the file in front of myvar)

Dan

new topic     » topic index » view message » categorize

2. Re: RENAME problem: directories with spaces?

Dan Moyer wrote:
> 
> 
> Juergen's suggestion for using "rename" with "system" command,  
> }}}
<eucode>
> sequence myvar
> myvar = "\"the old.txt\" \"the new.txt\""    -- or whatever is required
> system("rename " & myvar, 2)
> </eucode>
{{{

> seems like it should have worked, but didn't; I get an error about
>  "bad command format", but when I make it print out, it looks fine, except:
>  
> 
> the path to the file(s) includes more than one directory with SPACES in them,
> which I think is the problem, and I vaguely remember that there's a "trick"
> to making directories with spaces work, but I don't rember what it IS.
> 
> Is there such a trick?  (& what is it if there is)
> (in the code example above, I put the path to the file in front of myvar)
> 
> Dan

Hi Dan,

Can you use the Win API here?

Take care,
Al

E boa sorte com sua programacao Euphoria!


My bumper sticker: "I brake for LED's"

 From "Black Knight":
"I can live with losing the good fight,
 but i can not live without fighting it".
"Well on second thought, maybe not."

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

3. Re: RENAME problem: directories with spaces?

Dan Moyer wrote:

> Juergen's suggestion for using "rename" with "system" command,
> }}}
<eucode>
> sequence myvar
> myvar = "\"the old.txt\" \"the new.txt\""    -- or whatever is required
> system("rename " & myvar, 2)
> </eucode>
{{{

> seems like it should have worked, but didn't; I get an error about
>  "bad command format", but when I make it print out, it looks fine, except:
> 
> 
> the path to the file(s) includes more than one directory with SPACES in them,
> which I think is the problem, and I vaguely remember that there's a "trick"
> to making directories with spaces work, but I don't rember what it IS.
> 
> Is there such a trick?  (& what is it if there is)
> (in the code example above, I put the path to the file in front of myvar)

When there are spaces inside a file or directory name or path, it must
be enclosed in double quotes. That's why in my example above I did NOT
write
myvar = "the old.txt the new.txt"

but
myvar = "\"the old.txt\" \"the new.txt\""


This works fine here with EXW.EXE 2.5 on Windows 98, when "the old.txt"
is a file as well as a directory. Now I tried a directory name that
contains a path, e.g.
sequence myvar
myvar = "\"c:\\temp\\the old\" \"c:\\temp\\the new\""
system("rename " & myvar, 2)


and, strange enough, I get the message:
"Invalid parameter - c:\temp\the new".

But by virtue of the infinite wisdom of M$, when the _new_ name doesn't
contain a path at all, everything seems to work fine:
sequence myvar
myvar = "\"c:\\temp\\the old\" \"the new\""
system("rename " & myvar, 2)


As a general solution, I think something like the following can be used:
procedure rename (sequence oldNameWithPath, sequence newNameWithoutPath)
   -- rename a file or directory (both names may contain spaces)
system(sprintf("rename \"%s\" \"%s\"", {oldNameWithPath,
   newNameWithoutPath}), 2)
end procedure


Regards,
   Juergen

-- 
Who is general fault, and why does he read my hard disk?

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

4. Re: RENAME problem: directories with spaces?

Juergen Luethje wrote:
> 
> Dan Moyer wrote:
> 
> > Juergen's suggestion for using "rename" with "system" command,
<snip>
 > seems like it should have worked, but didn't; I get an error about
> >  "bad command format",
<snip>
> > the path to the file(s) includes more than one directory with SPACES in
> > them,
> > which I think is the problem, and I vaguely remember that there's a "trick"
> > to making directories with spaces work, but I don't rember what it IS.
> > 
> > Is there such a trick?  (& what is it if there is)
> > (in the code example above, I put the path to the file in front of myvar)
> 
> When there are spaces inside a file or directory name or path, it must
> be enclosed in double quotes. That's why in my example above I did NOT
> write
> myvar = "the old.txt the new.txt"
> 
> but
> }}}
<eucode>
> myvar = "\"the old.txt\" \"the new.txt\""
> </eucode>
{{{

> 
> This works fine here with EXW.EXE 2.5 on Windows 98, when "the old.txt"
> is a file as well as a directory. Now I tried a directory name that
> contains a path, e.g.
> }}}
<eucode>
> sequence myvar
> myvar = "\"c:\\temp\\the old\" \"c:\\temp\\the new\""
> system("rename " & myvar, 2)
> </eucode>
{{{

> 
> and, strange enough, I get the message:
> "Invalid parameter - c:\temp\the new".
> 
> But by virtue of the infinite wisdom of M$, when the _new_ name doesn't
> contain a path at all, everything seems to work fine:
> }}}
<eucode>
> sequence myvar
> myvar = "\"c:\\temp\\the old\" \"the new\""
> system("rename " & myvar, 2)
> </eucode>
{{{

> 
> As a general solution, I think something like the following can be used:
> }}}
<eucode>
> procedure rename (sequence oldNameWithPath, sequence newNameWithoutPath)
>    -- rename a file or directory (both names may contain spaces)
>    system(sprintf("rename \"%s\" \"%s\"", {oldNameWithPath,
>    newNameWithoutPath}), 2)
> end procedure
> </eucode>
{{{

> 
> Regards,
>    Juergen
> 

Thanks again Juergen, I'll give it a try.

Dan

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

5. Re: RENAME problem: directories with spaces?

Al Getz wrote:

<snip>

> Hi Dan,
> 
> Can you use the Win API here?

The following code uses the Windows API:
include misc.e
include dll.e
include machine.e

atom Kernel32
integer MoveFile

if platform() = WIN32 then
   Kernel32 = open_dll("kernel32.dll")
MoveFile = define_c_func(Kernel32, "MoveFileA", {C_POINTER, C_POINTER},
   C_LONG)
end if

function rename (sequence oldName, sequence newName)
   atom lpszOldname, lpszNewname, ret

   lpszOldname = allocate_string(oldName)
   lpszNewname = allocate_string(newName)
   ret = c_func(MoveFile, {lpszOldname, lpszNewname})
   free(lpszOldname)
   free(lpszNewname)
   return ret                                          -- 0 on error
end function

-- Demo
-- In contrast to using system("rename ...", ...), here the new name
-- can and must contain the appropriate path.
? rename("c:\\temp\\the old one", "c:\\temp\\the new one")


Regards,
   Juergen

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

6. Re: RENAME problem: directories with spaces?

Dan Moyer wrote:

<big snip>

> Thanks again Juergen, I'll give it a try.

You're welcome!
When you've tried it, please tell me whether it works on your system,
and what system you are using.

Juer - always curious - gen smile

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

7. Re: RENAME problem: directories with spaces?

Al Getz wrote:
> 
> Dan Moyer wrote:
> > 
> 
> Hi Dan,
> 
> Can you use the Win API here?
> 
> Al

Al, 
I didn't know how to, but Juergen's example for "system" worked just fine,
but thanks for the suggestion anyway. :)
Dan

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

8. Re: RENAME problem: directories with spaces?

Juergen Luethje wrote:
> 
> Dan Moyer wrote:
> 
> <big snip>
> 
> > Thanks again Juergen, I'll give it a try.
> 
> You're welcome!
> When you've tried it, please tell me whether it works on your system,
> and what system you are using.
> 
> Juer - always curious - gen smile

Worked FINE!  :)
Using WinXP Home Ed, SP2

Dan

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

9. Re: RENAME problem: directories with spaces?

The subject of this thread certainly is NOT
"Digest for EUforum at topica.com, issue 6085"

Cuvier Christian wrote:

>> posted by: Dan Moyer <danielmoyer at prodigy.net>
>>
>>
>> Juergen's suggestion for using "rename" with "system" command,
>> }}}
<eucode>
>> sequence myvar
>> myvar = "\"the old.txt\" \"the new.txt\""    -- or whatever
>> is required
>> system("rename " & myvar, 2)
>> </eucode>
{{{

>> seems like it should have worked, but didn't; I get an error about
>>  "bad command format", but when I make it print out, it looks
>> fine, except:
>>
>> the path to the file(s) includes more than one directory with
>> SPACES in them,
>> which I think is the problem, and I vaguely remember that
>> there's a "trick"
>> to making directories with spaces work, but I don't rember what it IS.
>>
>> Is there such a trick?  (& what is it if there is)
>> (in the code example above, I put the path to the file in
>> front of myvar)
>>
>> Dan
>>
> 
> To pass directory names with spaces or other non alpha characters in it, you
> only have to surround them with double quotes, as in

"only" is false.

> rename "C:\Program Files\test" "C:\Program Files\old test"
> 
> which needs the following Eu code to be issued:
> 
> }}}
<eucode>
> system(
> "rename \"C:\\Program Files\\test\" \"C:\\Program Files\\old test\""
> ,2)
> </eucode>
{{{


Code like this does not work on my system, see
<http://www.listfilter.com/EUforum/m9587.html>.

Regards,
   Juergen

-- 
Who is general fault, and why does he read my hard disk?

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

10. Re: RENAME problem: directories with spaces?

Dan Moyer wrote:
> 
> Al Getz wrote:
> > 
> > Dan Moyer wrote:
> > > 
> > 
> > Hi Dan,
> > 
> > Can you use the Win API here?
> > 
> > Al
> 
> Al, 
> I didn't know how to, but Juergen's example for "system" worked just fine,
> but thanks for the suggestion anyway. :)
> Dan

Hi Dan,

Oh ok good, i wasnt sure if you were using Windows or Linux.


Take care,
Al

E boa sorte com sua programacao Euphoria!


My bumper sticker: "I brake for LED's"

 From "Black Knight":
"I can live with losing the good fight,
 but i can not live without fighting it".
"Well on second thought, maybe not."

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

11. Re: RENAME problem: directories with spaces?

Dan Moyer wrote:
> 
> 
> Juergen's suggestion for using "rename" with "system" command,  
> }}}
<eucode>
> sequence myvar
> myvar = "\"the old.txt\" \"the new.txt\""    -- or whatever is required
> system("rename " & myvar, 2)
> </eucode>
{{{

> seems like it should have worked, but didn't; I get an error about
>  "bad command format", but when I make it print out, it looks fine, except:
>  
> 
> the path to the file(s) includes more than one directory with SPACES in them,
> which I think is the problem, and I vaguely remember that there's a "trick"
> to making directories with spaces work, but I don't rember what it IS.
> 
> Is there such a trick?  (& what is it if there is)
> (in the code example above, I put the path to the file in front of myvar)
> 
> Dan

Hello Dan,

sorry to be late, but I met a similar problem in downloading filenames 
with spaces inside, like "FILE Name.ext". Te result was a "Bad Request"
page answer by the server, as the system searched just the file "FILE"
and ignores the whole " Name.ext".

The trick there consisted in replacing the spaces with "%20", i.e.
"FILE%20Name.ext". Don't have time to test this now, but this answer 
can be useful however, or introduce to something like, so here it is.

antonio

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

12. Re: RENAME problem: directories with spaces?

I use a script to purge multiple files in differnt directories based 
on date retention. I wound up having Euphoria create a 
dynamic batch file with the list of files\paths to be deleted and just
used system_exec on that. 



--"ask about our layaway plan".
--

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

Search



Quick Links

User menu

Not signed in.

Misc Menu