Re: RENAME problem: directories with spaces?
- Posted by Juergen Luethje <j.lue at gmx.de> Sep 04, 2006
- 568 views
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?