Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Rename Files Recursively Through Prompt


  • Please log in to reply
6 replies to this topic

#1 Slim Nelson

Slim Nelson

  • Members
  • 223 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:USA
  • Local time:10:39 PM

Posted 31 October 2015 - 02:06 PM

Hey guys. Just need come command prompt help.

 

How do I rename a bunch of files recursively?

 

For example, say I have a bunch of video files like:

 

Example S01E01

Example S01E02

Example S01E03

Example S01E04

Example S01E05

etc...

 

Using the command prompt, how do I rename all the files to:

 

S01E01

S01E02

S01E03

S01E04

S01E05

etc...

 

Just take a word out of every file. I'm sure it's really easy but can't figure it out. Everything I find online shows me only how to rename a single file, it doesn't have information on options like /f, /R, etc to do it recursively.


Hulk_Tag.png


BC AdBot (Login to Remove)

 


#2 hamluis

hamluis

    Moderator


  • Moderator
  • 55,264 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Killeen, TX
  • Local time:10:39 PM

Posted 31 October 2015 - 05:24 PM

Rather than use Windows for such...you may want to take a look at a tool I use for renaming, Bulk Rename Utility .

 

Louis



#3 Slim Nelson

Slim Nelson
  • Topic Starter

  • Members
  • 223 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:USA
  • Local time:10:39 PM

Posted 31 October 2015 - 06:04 PM

I understand why you would recommend that and I appreciate your input but I'd rather use the command prompt.

 

Anyone know a good website that explains common commands and their options?


Hulk_Tag.png


#4 JohnC_21

JohnC_21

  • Members
  • 22,660 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:11:39 PM

Posted 31 October 2015 - 06:18 PM

You can use PowerShell as explained here. For your example you would not be replacing Example with another name so you would use nothing but after the renaming you may have a blank space in front of the name.

 

For your example the command would be

Get-ChildItem -Filter "*Example*" -Recurse | Rename-Item -NewName {$_.name -replace 'Example','' }

Edited by JohnC_21, 31 October 2015 - 06:18 PM.


#5 RolandJS

RolandJS

  • Members
  • 4,482 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Austin TX metro area
  • Local time:10:39 PM

Posted 31 October 2015 - 06:39 PM

There is a way.  Obviously, you will have to major-league tweak this:

 

IF EXIST C:\HOLD1\CCMTEXT5.TXT DEL C:\HOLD1\CCMTEXT5.TXT>NUL
IF EXIST C:\HOLD1\CCMTEXT4.TXT REN C:\HOLD1\CCMTEXT4.TXT CCMTEXT5.TXT>NUL
IF EXIST C:\HOLD1\CCMTEXT3.TXT REN C:\HOLD1\CCMTEXT3.TXT CCMTEXT4.TXT>NUL
IF EXIST C:\HOLD1\CCMTEXT2.TXT REN C:\HOLD1\CCMTEXT2.TXT CCMTEXT3.TXT>NUL
IF EXIST C:\HOLD1\CCMTEXT1.TXT REN C:\HOLD1\CCMTEXT1.TXT CCMTEXT2.TXT>NUL
IF EXIST C:\HOLD1\CCMTEXT.TXT  REN C:\HOLD1\CCMTEXT.TXT  CCMTEXT1.TXT>NUL

 

You can drop the >NUL if you want to see what is happening


Edited by RolandJS, 31 October 2015 - 07:17 PM.

"Take care of thy backups and thy restores shall take care of thee."  -- Ben Franklin revisited.

http://collegecafe.fr.yuku.com/forums/45/Computer-Technologies/

Backup, backup, backup! -- Lady Fitzgerald (w7forums)

Clone or Image often! Backup... -- RockE (WSL)

"I heard Spock finally got colander!"  "I believe the word is Kolinahr."  "Oh."


#6 Slim Nelson

Slim Nelson
  • Topic Starter

  • Members
  • 223 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:USA
  • Local time:10:39 PM

Posted 02 November 2015 - 09:15 PM

Thanks John and Roland, I got it to work.

 

PowerShell is pretty nice compared to the command prompt.

 

But damn, it's crazy how much more command work is needed when compared to just using the Linux terminal.


Hulk_Tag.png


#7 JohnnyJammer

JohnnyJammer

  • Members
  • 1,114 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:QLD Australia
  • Local time:01:39 PM

Posted 02 November 2015 - 10:17 PM

It depends on how you do it.

%a:~0,5% would set the first 5 characters.

Rememebr you can utilize .NET through powershell as well mate, handy for regular expressions.

Anyway something like so would do this.

@echo off
set str1=Example S01E01
set str2=%str1:Example =%
echo %str2%

Edited by JohnnyJammer, 02 November 2015 - 10:23 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users