0

Ok, let me give you the specifics

I have need to remove a character from every folder in a directory and replace it with a space.

I am working on organizing a folder, so I have a batch to make folders based on file names, this works actually very well

Where I got the files from however has _ in place of spaces, which for the individual files themselves, ok, that works, no real problem, but I now have 150 folders and counting that instead of just deleting the ending text I have to individually replace _ with spaces

here let's give an example of what I want

(asdf678)_Ok_here_is_the_file/folder_name_-_Someletters1231__(234jh2nbs)

to

(asdf678) Ok here is the file/folder name - Someletters1231 (234jh2nbs)

One final note, I have already moved files into all the folders at the time I realized this is a problem, so is it possible to do this in a way that doesn't disrupt the files inside? I had an old batch that ate files because it pushed them into the folder it made regardless of character limits.

-edit-

I should mention im on windows 7,

1 Answers1

0

Does this help https://superuser.com/questions/295994/how-do-i-rename-files-with-spaces-using-the-linux-shell/295997?

rename '_' ' ' [filenames...]

Or another approach from same source:

for f in *\_*; do mv "$f" "${f//_/ }"; done

Where

  • _ selects all files with underscore
  • ${f//str/new_str} is a bash-specific string substitution feature. All instances of str are replaced with new_str (quoted from source)

.bat file (source: How to rename file by replacing substring using batch in Windows)

@echo off
Setlocal enabledelayedexpansion

Set "Pattern=rename"
Set "Replace=reuse"

For %%# in ("C:\Folder\*.jpg") Do (
    Set "File=%%~nx#"
    Ren "%%#" "!File:%Pattern%=%Replace%!"
)

Pause&Exit
Justin Wilson
  • 330
  • 3
  • 17
  • If possible I would like to get this in a .bat file, If only because I'm able to drop it in the folder, launch the file, it does its thing and I can save it for the next time it needs/can be used. also, im on windows 7, i'm fairly sure the linux way wont help me but thanks – Kyle Harder Sep 05 '18 at 17:44
  • Makes sense. I did this with a .bat file but don't have access to the file right now. I'll update answer later. For now, I think https://stackoverflow.com/questions/16128869/how-to-rename-file-by-replacing-substring-using-batch-in-windows should help – Justin Wilson Sep 05 '18 at 17:58
  • Thanks, though I have to point out i'm here largely because programs that do what I want don't exist and its either I spend the next 50-100 hours making folders myself, let the problem sit, and do it again or find some way to do it myself. making folders on file names was easy enough, and altering the code to not automatically move files was easy because it was near plain english... but this, I think I know how to make it work in the folder its dropped in, buy beyond that I have no idea how I edit it to make it replace _ with space, I do appreciate any help – Kyle Harder Sep 07 '18 at 13:28