ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE. Software > Finished Programs

DONE: In Single Filename Change Spaces To Underscores


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

From StackOverflow


--- Code: Text ---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


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!


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.

Wow, 4wd, no idea what you're doing there.-nkormanik (April 01, 2018, 05:02 AM)
--- End quote ---

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?

Thanks, 4wd.   :Thmbsup:  I'll mark this done and move it.


[0] Message Index

Go to full version