Rename Folder

R

rn5a

An inquisitive question......

A ListBox lists all the directories & files residing in a directory on
the server. Assume that the ListBox lists 2 directories & 4 files. Also
assume that one of the directories is named 'mydir' (without the
quotes). Note that the all the letters in the directory name are in
lowercase.

To rename any directory/file, one can use the Move method of the
Directory/File class respectively but ASP.NET doesn't allow to JUST
change the case of a directory/file name. For e.g. if I want to change
the name of the directory from 'mydir' to 'MYDIR', ASP.NET generates
the following error:

Source and destination path must be different.

when the Move method of the Directory class is invoked. This, I
believe, is obvious because the Move method is primarily meant for
moving a directory/file from one location to another location.

Hasn't Microsoft included any method in the ASP.NET Framework to
exclusively rename a directory/file. Isn't there any way by which I can
change the directory name from 'mydir' to 'MYDIR'?

Though strictly speaking, changing the directory name from 'mydir' to
'MYDIR' doesn't amount to renaming; it's merely changing the case of
the directory name.

Note that if you navigate to 'mydir' from 'My Computer', then Windows
does allow users to change the directory name from 'mydir' to 'MYDIR'
i.e. Windows allows users to just change the case of a directory/file
name without generating any error.
 
H

Hans Kesting

This is because the Windows file system is not case-sensitive. What you have
to do is to create a temporary folder, move the contents of the "mydir"
folder to the temporary folder, delete the "mydir" folder, create a new
folder named "MYDIR," move the contents of the temp folder to the "MYDIR"
folder, and delete the temp folder.

couldn't you rename the temp folder to "MYDIR", after removing the
original "mydir"? Saves maybe a lot of copying.

Or now that I think about it some more, what about renaming "mydir" to
some different name ("mydir-temp") and then renaming that to "MYDIR"?
Both would be "real" renames to a case-insensitive filesystem.

Hans Kesting
 
M

Mark Rae

Or now that I think about it some more, what about renaming "mydir" to
some different name ("mydir-temp") and then renaming that to "MYDIR"?

That's certainly the way I do it...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top