Remove Spaces from File Names
Spaces in file names are a nightmare with the web; you deal with %20
and other nonsense when spaces are in file names. That's why when I receive images with spaces I cringe; I mean hell, dealing with spaces of file systems sucks too.
Anyways, I use the following command to remove spaces in file names within a directory:
# Replace spaces in file names with "-"
for f in *\ *; do mv "$f" "${f// /-}"; done
In this case I replace spaces with a dash. You can omit the dash if you'd rather there be nothing in place of spaces; underscores is another common pattern.
This script is not recursive, so it wont dive into subdirectories -- I don't usually have that case.
You've probably heard the talk around the water cooler about how promises are the future. All of the cool kids are using them, but you don't see what makes them so special. Can't you just use a callback? What's the big deal? In this article, we'll...
MooTools has always gotten a bit of grief for not inherently using and standardizing namespaced-based JavaScript classes like the Dojo Toolkit does. Many developers create their classes as globals which is generally frowned up. I mostly disagree with that stance, but each to their own. In any event...
Modern browsers are nice in that they allow you to style some odd properties. Heck, one of the most popular posts on this blog is HTML5 Placeholder Styling with CSS, a tiny but useful task. Did you know you can also restyle the textarea resizer in WebKit...
I love that JavaScript toolkits make enhancing web pages incredibly easy. Today I'll cover an effect that I've already coded with MooTools: creating a Twitter-style animated "Sign In" button. Check out this five minute tutorial so you can take your static...
https://gist.github.com/dbswebsite/f7ff88850dcf01fdafab5e66186cbdec
I *looooove* this! Nice work!
Is there a way to reverse this process? I get file names from the web that have no spaces. I want to put them back in. For example: HowToCookATurkey.txt would return to How To Cook A Turkey.txt
I haven’t found any of the renaming programs out there that tell you how to do it. Thanks in advance.
you’re a lifesaver! thx!
New to coding so need some help. Trying to figure out how to edit you code to work for my issue. Have a file, “Outfile-ABC-123 456 789.txt” in a directory, “//dev/out/file/” which has empty spaces in the file name which I need to replace the them with “0” or delete them all together whichever is simpler. Is the code below correct to help resolve my issue? Thanks in advance.
Before: “Outfile-ABC-123 456 789.txt”
After: “Outfile-ABC-12304560789.txt” or “Outfile-ABC-123456789.txt”
My version of your code edited.
for “Outfile-ABC-*” in (“\\Dev\Out\File\”;) do (mv “$Outfile-ABC-*” “${Outfile-ABC-*// /0}”); done