topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday April 16, 2024, 11:15 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: DONE: In Single Filename Change Spaces To Underscores  (Read 5518 times)

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 552
    • View Profile
    • Donate to Member
DONE: In Single Filename Change Spaces To Underscores
« on: April 01, 2018, 02:42 AM »
Looking for a tiny program that can be used in a batch file as follows:

"(path\)ChangeSpace2Underscore.exe" "%1"

The original file will then have any spaces in name converted to underscores.  File will remain in same initial subdirectory.

Any help appreciated.

Nicholas Kormanik


4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,643
    • View Profile
    • Donate to Member
Re: In Single Filename Change Spaces To Underscores
« Reply #1 on: April 01, 2018, 03:23 AM »
From StackOverflow

s2u.cmd

Code: Text [Select]
  1. cmd /e:on /v:on /c "for %%f in ("%~1") do (set "n=%%~nxf" & set "n=!n: =_!" & ren "%%~ff" "!n!" )"

Usage: s2u.cmd %1

Example: s2u.cmd "t e s t.txt"
Result: t_e_s_t.txt

FYI
« Last Edit: April 01, 2018, 08:00 PM by 4wd, Reason: Remove stupidity :/ »

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 552
    • View Profile
    • Donate to Member
Re: In Single Filename Change Spaces To Underscores
« Reply #2 on: April 01, 2018, 05:02 AM »
Wow, 4wd, no idea what you're doing there.  But it works!

And in such short time after my asking.

I placed your batch file into a special reserved location.  Created a shortcut to that batch file, and put it into my SendTo folder.  Then, selecting a file, right-click to bring up context menu, SendTo your batch file....  Presto.  Spaces changed to underscore, right where it sits.

Terrific job, 4wd.  Thanks a million!

Nicholas

P.S. -- Why this request to begin with?  A finicky program that won't accept being 'sent' a file if there are spaces in the filename, or even in the path.  Go figure.  But good now.


4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,643
    • View Profile
    • Donate to Member
Re: In Single Filename Change Spaces To Underscores
« Reply #3 on: April 01, 2018, 05:43 AM »
Wow, 4wd, no idea what you're doing there.

I didn't do anything except a search and repackage into a stand alone command file.

I would have done it as a short PowerShell script but why re-invent the wheel?
« Last Edit: April 01, 2018, 06:32 AM by 4wd, Reason: GFU »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: In Single Filename Change Spaces To Underscores
« Reply #4 on: April 03, 2018, 02:18 PM »
Thanks, 4wd.   :Thmbsup:  I'll mark this done and move it.