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

Replacing Spaces With Underscores

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

  1. nchernoff

    nchernoff Administrator
    Staff Member

    Joined:
    May 16, 2008
    Messages:
    42
    Likes Received:
    2
    Migrated From JP Software Wiki

    Underscore.btm displays all files in a folder in a point-and-shoot menu and for filenames selected it replaces all 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.

    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. Instead of echo, TEXT -- ENDTEXT can be used to create a large multi-step batch file.

    Batch file code

    Code:
    :  underscore.btm
    :  by Joseph "Rick" Reinckens
    :
    :  Displays all files in a folder in a point-and-shoot menu
    :  For filenames selected it replaces all spaces with underscores
    
    :  FUNCTION underscore %@replace[ ,_,%1]
    @echo off
    
    :  Create a temporary batch file
    echo `rename %1 %@replace[ ,_,%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