Windows CLI way to copy to the same directory and only change the case of the filename?
I have Windows 10 pro, with NTFS. I think the filesystem is fully case-sensitive. I can have the file Bill_and_Ted.txt in a directory, and write scripts that won't mistake it for bill_and_ted.txt. Linux WSL apps accessing NTFS directories are fully case-sensitive. But it seems that Windows utilities get confused.
So NTFS is probably case sensitive, but perhaps Windows is not. Is it possible in Windows to create two files in the same directory that only differ in ASCII case?
For various software development reasons, I would like to have the files Bill_and_Ted.txt and bill_and_ted.txt in the same directory, and then change the content. But so far, Powershell Copy-Item and Windows xcopy refuse to copy to the same directory when the filenames differ only in case. They fail with "File cannot be copied onto itself"
Is there a built-in Windows way to copy to the same directory and only change the case of the filename?
Solution 1:
This may be helpful.
https://superuser.com/a/412413/1176865
Go to the directory and run the following command:
for /f "Tokens=*" %f in ('dir /l/b/a-d') do (rename "%f" "%f")
Here is the break-down in case someone wants to modify/improve :
-
for /f
- For every line -
"Tokens=*"
- Process each item in every line. -
%f in (...)
-%f
is your variable name for every item. -
dir
- lists every file and subdirectory in a directory. -
/l
- (parameter for dir) Uses lowercase. -
/b
- (parameter for dir) Uses bare format, only the file/directory names, no size, no headers. -
/a-d
- (parameter for dir) Do not list directories. (a
stands forattribute
,-
stands fornot
andd
stands fordirectory
). -
rename "%f" "%f"
- rename the file with its own name, which is actually lowercased by thedir
command and/l
combination.
Solution 2:
The Short answer is, as long as you are using windows it will not work. Windows API does not support case sensitive.
in reference to : https://stackoverflow.com/questions/33998669/windows-ntfs-and-case-sensitivity