Page 1 of 1

how do you rename a file or a dir or a string name to be lowered?

Posted: 25 Sep 2024 00:12
by nnnmmm
https://mega.nz/file/HcgTVDbY#pkPHdT5Vt ... QOsPAm2_eY

i made a context menu entry "DO lower case"
if i RIGHT-click on a LNK file name or a LNK dir name or an explorer's file name or an explorer's dir name, you can also get an entry "DO lower case" included in as a possible choice as it can be seen on the link posted above

"DO lower case" will trigger to run one of "Context Menu - DO lowercase - Dir.bat" or "Context Menu - DO lowercase - File.bat"

"Context Menu - DO lowercase - Dir.bat" has the content below
@ECHO OFF
SET Rename_string2lowercase="%~1"
FOR /F "Tokens=*" %%V in ('DIR /L /B %Rename_string2lowercase%' ) DO (rename "%%V" "%%V")

it must not do whole directory branches or a list of all files in the current directory. it must change only one targeted string name

PS)
later i kind of fixed it, dumb of me i did it on exFAT
it didnt work on LNK files
i still have a problem renaming a directory, the rename command seems to only work on files.

Re: how do you rename a file or a dir or a string name to be lowered?

Posted: 25 Sep 2024 05:34
by Aacini
Yes. The on screen help on REN command clearly specify:
REN /? wrote: Change the name of one or more files.
On the other hand, the help on MOVE command indicate:
MOVE /? wrote: Move files and change the name of files and directories.
Antonio

PS - You should try to be much clear on your descriptions. Your problem is to rename a directory, not to rename a file or a string. Period. (What "rename a string" means?) The lowercase point have no relation to the problem of rename a directory. And the confusing description of what your program does has absolutely no bearing on the core problem and just distract us.

Try to be concise and clearer...

Re: how do you rename a file or a dir or a string name to be lowered?

Posted: 25 Sep 2024 22:15
by nnnmmm
>Yes. The on screen help on REN command clearly specify:
thanks

i understood many parts of it
i got the two solutions out of three
-------------------------------------------------------
Context Menu - DO lowercase - Dir.bat has
@ECHO OFF
SET Rename_string2lowercase="%~dp1"
FOR /F "Tokens=*" %%V in ('DIR /AD /B /L %Rename_string2lowercase%' ) DO (RENAME "%%V" "%%V")

::%~dp0 location of this batch file
::%~dp1 location of the cursor of explorer
::%~dp2 none
::ren's target name must not have a path attached to it
-----------------------------------------------------
Context Menu - DO lowercase - File.bat
@ECHO OFF
::all 3 work
::SET Rename_string2lowercase="%~1"
::SET Rename_string2lowercase="%~n1%~x1"
SET Rename_string2lowercase="%~nx1"
FOR /F "Tokens=*" %%V in ('DIR /B /L %Rename_string2lowercase%' ) DO (RENAME "%%V" "%%V")
----------------------------------------------------
when i right-click on a desktop icon,it sends me to the source of the linked file or dir and not the filename.lnk itself
how would i get to the filename.lnk itself?

Re: how do you rename a file or a dir or a string name to be lowered?

Posted: 02 Oct 2024 20:53
by nnnmmm
my previous posted "Context Menu - DO lowercase - Dir.bat" turned out to be incorrect

Context Menu - DO lowercase - Dir.bat. this is the correct one
@ECHO OFF
SET "str1=%~dp1"
SET "str2=%~dpn1"
ECHO "%str1%"
ECHO "%str2%"
ECHO "%str2:~-3%"

IF /I "%str2%"=="%str2:~-3%" GOTO :END
FOR /F "Tokens=*" %%V in ('DIR /AD /B /L %str1%') DO (RENAME "%str2%" "%%V")

:END
EndLocal
@EXIT

::%%~dp1 parent dir of the current location of the explorer's cursor
::%%~dpn1 current location of the explorer's cursor, revealed the secret of current dir

~dpn1 was not in the FOR /? but how did i find it? just pure luck and my habit of writing a batch with "trial and error" tactics
i came across a ztree batch that used ~dpn1 about 2 weeks ago by blind luck, i decided to type in and see what it could do, then the magic happened.