Author Topic: Rename file functionality  (Read 7328 times)

Offline skirby

  • Almost regular
  • **
  • Posts: 137
Rename file functionality
« on: July 04, 2007, 10:56:53 am »
Hello,

I have a question about Rename File functionality.
For example, I would like to rename file from main.h to Main.h
Code::Blocks display an error message (see below)


Is it normal behavior or is it a bug?


Thanks and have a nice day.

Offline kkez

  • Almost regular
  • **
  • Posts: 153
    • WinapiZone
Re: Rename file functionality
« Reply #1 on: July 04, 2007, 01:16:33 pm »
Did you read that error by any chance? It says Main.h already exists, so it cannot rename the file (that would mean overwrite the file, is this what you want?).

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: Rename file functionality
« Reply #2 on: July 04, 2007, 01:25:38 pm »
thanks to windows : not case sensitive

Offline skirby

  • Almost regular
  • **
  • Posts: 137
Re: Rename file functionality
« Reply #3 on: July 04, 2007, 01:31:03 pm »
Hello kkez,

Sure I have read the message.
What I want to do is rename Main.h in main.h like you could do in windows Explorer.

In fact, I would like to know if is it normal that C::B isn't able to rename a file with the same name but with a different case.

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Rename file functionality
« Reply #4 on: July 04, 2007, 03:04:38 pm »
I've had that problem in Windows outside codeblocks.

Here's your howto:

1) ren Main.h dummy.h
2) ren dummy.h main.h

:) ta-da!

Offline skirby

  • Almost regular
  • **
  • Posts: 137
Re: Rename file functionality
« Reply #5 on: July 04, 2007, 03:48:52 pm »
Hi rickg22,

I know this way (hopefully for me)  :P
But, do you think it could be integrated into C::B?

It works with Visual C++ Express IDE so I am sure it could be done into C::B.

Do you want me to add a feature request on BerliOS?

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Rename file functionality
« Reply #6 on: July 04, 2007, 05:45:29 pm »
Yes, please.

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Rename file functionality
« Reply #7 on: July 04, 2007, 05:53:08 pm »
Do you want me to add a feature request on BerliOS?

You should put the request to wx devs.

C::B uses ::wxRenameFile() function to rename a file. If it returns false C::B throws that error message. So this function should be able to detect such cases.
Be a part of the solution, not a part of the problem.

Offline raph

  • Almost regular
  • **
  • Posts: 242
Re: Rename file functionality
« Reply #8 on: July 07, 2007, 03:55:42 pm »
C::B uses ::wxRenameFile() function to rename a file. If it returns false C::B throws that error message. So this function should be able to detect such cases.
Just set the overwrite flag in this case and you are fine.
I've submitted a patch (#002089).

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Rename file functionality
« Reply #9 on: July 09, 2007, 10:22:51 am »
There is nothing to fix, as this is intended behaviour. I don't know why it's intended, but it is.

The way I had originally implemented that function would just rename the file, overwriting a possibly existing file. This of course assumes a basic amount of diligence from the user's part, but I did not deem that as a problem.
Code::Blocks is not thought to replace Windows Explorer, it only contains that function to make your life easier when you need to rename files in your project (so renaming on the file system and in the project is one operation).

Later, it was found that if you provide users with a way to rename files and allow them to overwrite an existing file, they will do it 20 times per day, and they will never learn it. Neither will they see that they're doing something wrong. Thus, functionality was added to check for existence before overwriting a file (therefore, setting the overwrite flag is not an option).

Now, the problem is, Main.h and main.h are really the same file under Windows. I don't know why, it does not make sense to me, but this is intended behaviour ever since the days of DOS.
If you ask for Main.h, and main.h exists, you get main.h.

The only possibility to work around this (which is probably what Explorer and Visual Studio do, too) is to add an extra case-insensitive comparison, and silently overwrite files if that comparison returns equality.
But... no thank you! I think we'll rather live with the fact that Main.h can't be renamed into main.h under Windows than add such nasty hacks to work around deliberately wrong behaviour :)
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline raph

  • Almost regular
  • **
  • Posts: 242
Re: Rename file functionality
« Reply #10 on: July 09, 2007, 11:47:31 am »
I see your point :)
What about adding a "File %file% already exists. Do you want to overwrite it?" question (in my opinion even an annoyingdialog :D) and always setting the overwrite flag?

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Rename file functionality
« Reply #11 on: July 09, 2007, 03:34:05 pm »
There is nothing to fix, as this is intended behaviour. I don't know why it's intended, but it is.

intended by whom? "ren main.cpp Main.cpp" works fine from my command prompt (cmd.exe)

Quote
Later, it was found that if you provide users with a way to rename files and allow them to overwrite an existing file, they will do it 20 times per day, and they will never learn it. Neither will they see that they're doing something wrong.

Overwriting files is a valid operation. perhaps it is misleading to call it rename, though... Anyway, in this particular case, it shouldn't be an overwrite, it should just be a simple relabeling of the relevant file system entry.

Quote
Now, the problem is, Main.h and main.h are really the same file under Windows. I don't know why, it does not make sense to me

you aren't alone Thomas: :)
http://geekz.co.uk/lovesraymond/archive/mundane-name

On windows, URLs are case insensitive also. Although harder to code for and generally a cause of frustration for experienced users, I think the reason for case-insensitivity is obvious.