HOME | FERGUSON Digital Blog

Case Insensitive Directory Rename

ColdFusion Add comments

Ever tried to rename a directory to the same name but with different letter case through CFDIRECTORY? Does not work to well on a Microsoft Windows platform. Why? Unlike Linux, Windows sees the names "MyDirectory", "MYDIRECTORY", and "mydirectory" as the same. Here is a Java call through CFSCRIPT that will allow you to rename a folder between the different cases.

<cfscript>
   src=CreateObject("java", "java.io.File").init("c:\mydirectory");
   dest=CreateObject("java","java.io.File").init("c:\MyDirectory");
   src.RenameTo(dest);
</cfscript>

Remember, this works because Java is platform independent. For this reason, unlike CFDIRECTORY on a Windows machine, it won't see the three directory names in the paragraph above as the same item.

Obviously, you wouldn't want to hard code a directory rename. After all, it would run once, rename the directory and never run again. For this reason, for usability just substitute the two absolute folder names with variables that are selected through the process of your choice and design.

If you find this post useful please leave a comment and let me know how you used the information.

0 responses to “Case Insensitive Directory Rename”

Leave a Reply




© Copyright 1997-2024, All Rights Reserved Coldfusion and MS SQL2008
Powered by Mango Blog.   Design by FERGUSON Digital
o:Event name="beforeHtmlBodyEnd" />