1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Convert Filenames To Lowercase & Underscores

Discussion in 'T&T - Scripting' started by nchernoff, Jun 5, 2008.

  1. nchernoff

    nchernoff Administrator
    Staff Member

    May 16, 2008
    Likes Received:
    Migrated From JP Software Wiki

    Renlow_score.btm displays all files in a folder in a point-and-shoot menu and for filenames selected it converts the name to lowercase and replaces spaces with underscores.

    This is particularly useful when uploading to a Unix/Linux system files created in Windows, because Unix/Linux often automatically replaces spaces in filenames with "%20", in which case links to the uploaded files that still contain spaces in the names may not work. Also, directory and file names are not case-sensitive in Windows but are case-sensitive in Unix/Linux. Common practice in Unix/Linux is for path and file names to be entirely lowercase.

    Programming technique

    I tried using select with the @replace function and the rename command but they don't work together. The solution is to use echo to write code for a temporary batch file, have select call the batch file and then delete the batch file.

    If the text processing needed multiple steps, instead of echoing a single function line, TEXT -- ENDTEXT could write a large multi-step temporary batch file.

    Batch file code

    :  renlow_score.btm
    :  by Joseph "Rick" Reinckens
    :  Displays all files in a folder in a point-and-shoot menu
    :  For filenames selected it converts the name to all lowercase
    :  and replaces all spaces with underscores
    :  FUNCTION scorelow %@replace[ ,_,%@lower[%1]]
    @echo off
    :  Create a temporary batch file
    echo `rename %1 %@replace[ ,_,%@lower[%1]]`>c:\zztemp.btm
    select call c:\zztemp.btm (*.*)
    :  Delete the temporary file
    del c:\zztemp.btm /q
    Contributed by Rick Reinckens

Share This Page