Help with a Windows Cmd script


RobLI57

New member
Local time
11:30 AM
Posts
17
OS
Windows 11 Pro
Hi all,

I am looking for a way to extract mp3 files from a Zip file that I download each week. What I need to happen is to take 6 of the .mp3 files and rename them and move them to a specific folder on the same Windows C drive. I know how to use wild cards for files that change each week, but this is different. In this case, the files I need are labeled as follows:
001-1.mp3. renamed 5000.mp3
001-2.mp3. renamed 5001.mp3
002-1.mp3 renamed 5002.mp3
002-2.mp3 renamed 5003.mp3
003-1.mp3 renamed 5004.mp3
003-2.mp3 renamed 5005.mp3
These files are one hour radio programs (001, etc) that are broken into 30 min (-1, -2) segments, hence the naming convention. The file next week will continue with 004, 005, 006, etc.
Every other program that I receive from producers has a consistent filename so creating a script to rename them to the numbers I need was simple.
I don't know how to build a script file because of the changing filenames within each week.

Any help would be appreciated.
Thanks
Rob
 
Windows Build/Version
Windows 11

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    PC/Desktop
    CPU
    12th Gen Intel(R) Core(TM) i7-12700 2.10 GHz
    Memory
    16Gb
Rob,

There are three or four stages in your script. You don't say which ones you need help with.
my ditty Batch file and PowerShell guides [post #7] - ElevenForum

1 Unzip
I assume you do not have a zip utility such as WinZip. Such utilities have their own commands.
See Option 4 of Unzip (extract) Files from Zip folder - ElevenForumTutorials

2 Rename
That will just be a string of commands
ren 001-1.mp3 5000.mp3
ren 001-2.mp3 5001.mp3
ren 002-1.mp3 5002.mp3
ren 002-2.mp3 5003.mp3
ren 003-1.mp3 5004.mp3
ren 003-2.mp3 5005.mp3

3 Move
That will be a Move command, enter Move /? in a terminal [command prompt] window to see its Help file

4 Tidy up
There might be unused remnants in your original unzipped folder and you might or might not want to delete the original zip file.



Best of luck,
Denis



Welcome to ElevenForum.

It's really worth making time to browse through the ElevenForums Tutorial index - there's a shortcut to it at the top of every ElevenForum page [within the Tutorials dropdown list].
- At the foot of the ElevenForum Tutorial index is a shortcut to download it as a spreadsheet.
- I download a new copy each month.
- By downloading it as a spreadsheet I can benefit from Excel's excellent filtering capabilities when I search for topics of interest.
- ElevenForum tutorials are also listed at Tutorials and there's a shortcut to that at the top of every page.

You can search ElevenForum using the search box in the top-right corner of all ElevenForum webpages or using Advanced Search - ElevenForum
- You can also search ElevenForum threads in many general search engines, such as Google, by adding site:elevenforum.com after your search term. For example,
Taskbar setup site:elevenforum.com
- [This is what the search box in the top-right corner of ElevenForum webpages does automatically]
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
My apologies. I know how to unzip the file, I know how to move the files around. My issue is that I don't know how to do the rename. For example, here is a script that I use for other shows. Its easy because each week the filenames don't change. So renaming them to the numbers I need them to be is simple:
move C:\Users\Rob\Downloads\therockblock_the-rock-block-show*.zip D:\RockBlock\Zipped\
pause
"C:\Program Files\7-Zip\7z" e D:\RockBlock\zipped\*.zip -oD:\RockBlock\unzipped\


TIMEOUT /T 10

ren "D:\RockBlock\unzipped\THE ROCK BLOCK - SHOW * - PART 1.mp3" 5300.mp3
ren "D:\RockBlock\unzipped\THE ROCK BLOCK - SHOW * - PART 2.mp3" 5301.mp3
ren "D:\RockBlock\unzipped\THE ROCK BLOCK - SHOW * - PART 3.mp3" 5302.mp3
ren "D:\RockBlock\unzipped\THE ROCK BLOCK - SHOW * - PART 4.mp3" 5303.mp3


Move D:\RockBlock\unzipped\*.mp3 C:\PlayoutONE\Import\RockBlockInjest
Move D:\RockBlock\zipped\*.zip D:\RockBlock\archive\

end
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    PC/Desktop
    CPU
    12th Gen Intel(R) Core(TM) i7-12700 2.10 GHz
    Memory
    16Gb
My issue is that I don't know how to do the rename
renaming them to the numbers I need them to be is simple
ren "D:\RockBlock\unzipped\THE ROCK BLOCK - SHOW * - PART 1.mp3" 5300.mp3
ren "D:\RockBlock\unzipped\THE ROCK BLOCK - SHOW * - PART 2.mp3" 5301.mp3
ren "D:\RockBlock\unzipped\THE ROCK BLOCK - SHOW * - PART 3.mp3" 5302.mp3
ren "D:\RockBlock\unzipped\THE ROCK BLOCK - SHOW * - PART 4.mp3" 5303.mp3

So you seem know everything you need to know despite saying that you don't.


All the best,
Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
If I understand your question, this works:
Code:
for %n in (*.*) do ren "%n" "5%n"
 

My Computers

System One System Two

  • OS
    Windows 11
    Computer type
    PC/Desktop
    CPU
    AMD Ryzen 5 5600
    Motherboard
    MSI B550-A Pro
    Memory
    16 GB
    Graphics Card(s)
    Sapphire Radeon RX 6500XT (8 GB version)
    Monitor(s) Displays
    BenQ Mobuiz EX2710Q QHD, Iiyama ProLite X23377HDS
    Hard Drives
    MSI Spatium M461 4TB
  • Operating System
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Acer A114
    CPU
    Intel Celeron N4020
Hi Denis

Thanks for the response. Wish that was true!
The issue I have is that each show I get besides this one has consistent filenames:
THE ROCK BLOCK - SHOW * - PART 1.mp3 (the * is the only thing that changes, its the show number which changes each week.

On this show I need help with, so see that each segment is different and there's no way to use the wildcard to rename:
001-1.mp3 5000.mp3
001-2.mp3 5001.mp3
002-1.mp3 5002.mp3
002-2.mp3 5003.mp3
003-1.mp3 5004.mp3
003-2.mp3 5005.mp3

How do I use a wildcard to rename those files? They aren't consistent, and next weeks files will be
004-1.mp3
004-2.mp3
etc....
See my issue?
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    PC/Desktop
    CPU
    12th Gen Intel(R) Core(TM) i7-12700 2.10 GHz
    Memory
    16Gb
Rob,

You keep posting different name patterns for the original files.
Please explain exactly what is in the name pattern and which bits of that pattern determine what you want to rename the files to.
  • There is no problem using * in a Ren command as long as no two files fit the complete pattern.
  • If PART 1.mp3 etc really are in the filenames and they determine what you want them to be renamed to then the ren command is as I said.

Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
Hi Denis

Sorry for the confusion. Let me reset:

Each week I receive a Zip file which contains 3 one hour shows that are broken into two segments per hour. These shows are individual standalone shows so stations can choose to air one hour or up to three hours. I air all three hours each week as a three hour show. That's why there are 3 different episode numbers followed by the -1 -2 segment numbers in the Zip file.

I need to rename those files for ingestion into the radio automation software so they run when scheduled. The automation numbers assigned are: 5000 to 5005.

To illlustrate my issues, I posted a script of another program I run (The Rock Block) to show you what that script looks like to rename those files and move them to the automation system for ingestion. Then I save the zip file for possible replays, etc.

I tried to adjusting my Rock Block script on the new show, but it doesn't work because there are three different show numbers. This is when I realized that a simple wildcard didn't work.

I hope that clears it up. I am a windows script hack at best, I can sometimes find scripts and change them to suit my needs, or if I can make it work at the command prompt, then I know I can add it to a script, but anything that requires programming, I'm lost.

I just noticed that Iko just posted a line of code that would work: for %n in (.) do ren "%n" "5%n"
But I'm not sure what it replaces in the script, etc. Sorry for my lack of skills. :)
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    PC/Desktop
    CPU
    12th Gen Intel(R) Core(TM) i7-12700 2.10 GHz
    Memory
    16Gb
I do not believe that you will need to use any For commands. It's a powerful command that takes a lot of study & experimentation so, since there's no need to use it, I suggest you don't.

I still do not understand what the pattern of original filenames is. Please post a list and add the filenames you want to rename them to.

I can help you solve this problem once I see the patterns involved.


Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
1688397164376.png
Above is a screenshot of the unzipped files that are included in the zipped file. 261, 262 & 263 are their episode numbers. So next week, it will be 264, 265 & 266.
The files I need are the ones in the boxes. The other files are 1 segment designed for stations who don't need commercial placement. I do not need the other files. just those six.
Hope that helps.
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    PC/Desktop
    CPU
    12th Gen Intel(R) Core(TM) i7-12700 2.10 GHz
    Memory
    16Gb
This works for any number of MP3 files, assuming the original filenames are in the correct order. You can change the expression in DIR to match your source pattern.
Code:
@echo off
setlocal enabledelayedexpansion

set /a filenumber = 5000

for /f %%A in ('dir /b *.mp3') do (
   echo ren %%A !filenumber!.mp3
   set /a filenumber+=1
)
Code:
ren 001-1.mp3 5000.mp3
ren 001-2.mp3 5001.mp3
ren 002-1.mp3 5002.mp3
ren 002-2.mp3 5003.mp3
ren 003-1.mp3 5004.mp3
ren 003-2.mp3 5005.mp3
 

My Computer

System One

  • OS
    Windows 7
So you could detect
FPH ???-?

Please confirm how you use each entry in that list to decide the new name.
The easiest thing would be to
  • remove FPH{space}
  • remove the dash
giving you 2611, 2612, ..., 2661, 2662 etc each week. There'd be no need to change the script until you reached beyond episode 999-2.

Please confirm the original file extension. I think you said it was .mp3.

Contrary to what I said before, I think a For command might be needed for processing each one but that's not the end of the world & it depends on the new filename pattern you want.
I'll post a sample of how I would lay it out for you to try. I always use subroutines with For commands because I find that structure easier to debug.


Denis
 
Last edited:

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
Denis
Each week, those .mp3 files get renamed with the same numbers. Sorry, I was wrong about the cart numbers as you'll see below, its 5600 -5605.

Those numbers are what are called "Cart Numbers in the Automation Software, and each week those Cart numbers are overwritten with the new .mp3's. Here is a screenshot of them in the automation system:
1688398430875.png
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    PC/Desktop
    CPU
    12th Gen Intel(R) Core(TM) i7-12700 2.10 GHz
    Memory
    16Gb
those .mp3 files get renamed with the same numbers
How you do calculate those new names from the originals?
Can't you just use the 2611 etc I wrote about?

Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
I set a group of Cart numbers in the Automation system for each show I run. This show uses carts 5600 - 5605. Its just the way I organize the shows separate from music files, etc. I could have chosen any numbers I wanted really. The important thing is that whatever the numbers are in the automation system, that they remain constant from week to week for scheduling purposes. It get involved on my end because the schedule happens in my music scheduler, not in the automation system so it makes sense to assign a set of numbers once to a show and just use them week to week. Does that help?
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    PC/Desktop
    CPU
    12th Gen Intel(R) Core(TM) i7-12700 2.10 GHz
    Memory
    16Gb
So the first pair to match the pattern
FPH ???-?
will always be renamed 5600 & 5601 and so on?
1688399171485.png

And there will never be more than 3 pairs so that 5605 is never exceeded?


Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3447
Code:
@echo off
setlocal enabledelayedexpansion

set /a filenumber = %1

if "%~2"=="" (
   set regex=*.mp3
) else (
   set regex=%2
)

for /f "tokens=*" %%A in ('dir /b %regex%') do (
   echo ren %%A !filenumber!.mp3
   set /a filenumber+=1
)
Code:
C:\Users\GARLIN\Downloads\TheRock>rename.bat 5000
ren FPH 261-1.mp3 5000.mp3
ren FPH 261-2.mp3 5001.mp3
ren FPH 261.mp3 5002.mp3
ren FPH 262-1.mp3 5003.mp3
ren FPH 262-2.mp3 5004.mp3
ren FPH 262.mp3 5005.mp3
ren FPH 263-1.mp3 5006.mp3
ren FPH 263-2.mp3 5007.mp3
ren FPH 263.mp3 5008.mp3

C:\Users\GARLIN\Downloads\TheRock>rename.bat 5600 FPH*-*
ren FPH 261-1.mp3 5600.mp3
ren FPH 261-2.mp3 5601.mp3
ren FPH 262-1.mp3 5602.mp3
ren FPH 262-2.mp3 5603.mp3
ren FPH 263-1.mp3 5604.mp3
ren FPH 263-2.mp3 5605.mp3
 

My Computer

System One

  • OS
    Windows 7
Oh I understand what you're saying. The reason that I can't use the 2611 numbers is because when the files are renamed, they are sent to a specific folder for ingestion. If I don't use the same numbers, the Auto Importer program that is part of the Automation program won't ingest them properly into the system. It is expecting those numbers. I have 6 syndicated programs I run and each is assigned numbers starting at 5000. Then 5100's 5200's, etc. I use consecutive numbers depending on how many segments I have for each show. So, this is my 6th syndicated program, hence, 5600's.
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    PC/Desktop
    CPU
    12th Gen Intel(R) Core(TM) i7-12700 2.10 GHz
    Memory
    16Gb
To answer your question about 5605 being exceeded, you are correct. it will always be the same number of segments. 3 hours, and 2 segs per hour, or 6 total segments. Never exceeding 5605.
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    PC/Desktop
    CPU
    12th Gen Intel(R) Core(TM) i7-12700 2.10 GHz
    Memory
    16Gb
Thank you Denis, I will set this up. Is it okay for me to add the Unzip commands before and the move commands after your script that need to run? And if so, is there anything special that I need to do to the file to add them?
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    PC/Desktop
    CPU
    12th Gen Intel(R) Core(TM) i7-12700 2.10 GHz
    Memory
    16Gb

Latest Support Threads

Back
Top Bottom