1. change all files names to lower case.

Friends, why the code below does not work?

The intention is to change all files names to lower case.

But nothing is renamed. How should I do this?

 ff= dir(dd)  
 if atom(ff) then 
  ff= message_box("Folder " & dd &"\nNot found","","") 
  return 
 end if 
 for i=3 to length(ff) do 
  ll=dd&lower(ff[i][1]) 
  mm=moveFile(dd&ff[i][1],ll) 
  if mm=w32False then 
   xx= message_box("The file \n" & dd & ff[i][1]&"\n has not been renamed to \n"&ll,"","") 
  end if 
 end for 

Thanks in advance

new topic     » topic index » view message » categorize

2. Re: change all files names to lower case.

I'm not at a windows box at the moment, so this is just a guess:

MoveFile fails if the destination file already exists, which might be the what's happening since you're only changing the case of the filename and Windows is filename case-insensitive. Try using MoveFileEx with the flag MOVEFILE_REPLACE_EXISTING?

And if that doesn't work, try renaming it to temporary different name, then rename again to the lowercased name.

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

3. Re: change all files names to lower case.

I did not understand. Sorry...

MoveFileEx does not exist on or in Eu4 and Eu3

How to use this function?

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

4. Re: change all files names to lower case.

How about something like this?

include std/filesys.e 
include std/text.e 
 
if not rename_file(dd, lower(dd),1) then   
	puts(1,"Couldn't rename "&dd&"\n") 
end if  
new topic     » goto parent     » topic index » view message » categorize

5. Re: change all files names to lower case.

So, it worked.

I renamed twice.

The first time with a changed name

Later renamed to the correct name in lowercase

ff= dir(dd)
 if atom(ff) then  
  ff= message_box("Folder " & dd &"\nNot found","","")  
  return  
 end if  
 for i=3 to length(ff) do  
  ll=dd&lower(ff[i][1])  
  mm=moveFile(dd&ff[i][1],ll & "1") -- I added something in the name, only to record with different name 
  mm=moveFile(ll & "1",ll)          -- Now, recorded with the correct name 
  if mm=w32False then  
   xx= message_box("The file \n" & dd & ff[i][1]&"\n has not been renamed to \n"&ll,"","")  
  end if  
 end for  

But this seems a codig poorly done.

Does anyone have a better idea?

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

6. Re: change all files names to lower case.

sergelli said...

So, it worked. Does anyone have a better idea?

The only thing I'd change would be to test for when the double rename is necessary, then again the code posted seems to rename things that are already lowercase. Personally, I'd write a shim (completely untested):

procedure rename(sequence d, sequence oldname, sequence newname) 
    if not equal(newname,oldname) then 
        if equal(lower(oldname),lower(newname)) then 
            moveFile(d&oldname,d&oldname&'1') 
            oldname&='1' 
        end if 
        moveFile(d&oldname,d&newname) 
    end if 
end procedure 

Pete

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

7. Re: change all files names to lower case.

It's a good idea to avoid renaming the names that are already in lowercase.

But I believe there was more direct method, which avoided rename twice.

Thanks to all for the help.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu