• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Batch file rename

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

torin3

Member
Joined
Dec 25, 2004
I've got a legacy type problem. We switched from using an on-site system to using a managed server for our EDI communication at work. Seems to be working fine in general, except for a filename issue.

We used to get our 830 files named in this format Rxxxxxxx. with the x being hex numbers. Our Access program that updates our databases is set up to use this naming format, and I don't have the skills yet to change it.

The 830 files we are getting from the managed server look like this: 830_ib.EDI_20160924_231249_1442392

I can manually rename the files in about 15 to 20 minutes once a week. But I'd like to automate the process. Can anybody point me to a guide that would let me write a batch/cmd file that would take all 830_ib.x files and rename them in the Rxxxxxxx. style? The exact numbering isn't critical, they just need to not have duplicates and be 0123456789ABCDEF characters, other than the initial R.

Thanks!
 
I've got a legacy type problem. We switched from using an on-site system to using a managed server for our EDI communication at work. Seems to be working fine in general, except for a filename issue.

We used to get our 830 files named in this format Rxxxxxxx. with the x being hex numbers. Our Access program that updates our databases is set up to use this naming format, and I don't have the skills yet to change it.

The 830 files we are getting from the managed server look like this: 830_ib.EDI_20160924_231249_1442392

I can manually rename the files in about 15 to 20 minutes once a week. But I'd like to automate the process. Can anybody point me to a guide that would let me write a batch/cmd file that would take all 830_ib.x files and rename them in the Rxxxxxxx. style? The exact numbering isn't critical, they just need to not have duplicates and be 0123456789ABCDEF characters, other than the initial R.

Thanks!

For Windows (I know this works on Win7 and Win10 but no idea anywhere else) Select all files in the directory > right click the first one and "rename" > select your name and hit Enter. All files will change to the chosen name appended with a number. http://www.howtogeek.com/111859/how...s-in-windows-4-ways-to-rename-multiple-files/ <--- recently had this question myself :D

For Linux: Lots of stuff out there, pick your poison. I can recommend one if you cant find one you like, as Ive tried 2 or three, but ive run across nearly limitless different ones every time I search.
 
Assuming you're on Vista, 7, 8, or 10, Powershell can knock this out pretty easily. Batch sucks, stop using it.

Some pseudo-code (don't try to use this, it won't work):
Code:
$files = Get-ChidItem C:\path\to\your\files\*ib.EDI*
$counter = 0
for ($file in $files)
{
  $newName = "whatever_ib.EDI_${counter}"
  Move-Item $file.Name $newName
}
counter++
}
 
Back