• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 549
  • Last Modified:

Script to Run Command Using Filenames With Wildcards

Hey Guys -

About 3-4 times a week, I have a script which downloads 5 mp3 files to a folder.  After download, I manually combine these mp3 files into a single file which I move to a new folder .  I've been able to automate the download part of it, but am trying to find a way to script the merging of the files.  

I've already found a command line utility which will join them - mp3wrap - which I've tested successfully.  Basically, I just need to know how to put it all together.  Below are all the variables which would be involved:

Format of file names of all 5 files
Note: The date in the file will always be the same as they date they are downloaded
show_128k_12-01-2014_part001of05.mp3
show_128k_12-01-2014_part002of05.mp3
show_128k_12-01-2014_part003of05.mp3
show_128k_12-01-2014_part004of05.mp3
show_128k_12-01-2014_part005of05.mp3

Command line string which would be used to join the above files using mp3wrap
Format: mp3wrap OUTPUT.mp3 file1.mp3 file2.mp3...
mp3wrap show_128_12-01-2014_combined.mp3  show_128k_12-01-2014_part001of05.mp3 show_128k_12-01-2014_part002of05.mp3 show_128k_12-01-2014_part003of05.mp3 show_128k_12-01-2014_part004of05.mp3 show_128k_12-01-2014_part005of05.mp3

Open in new window


Ideas
Even putting this into a batch file and running via Windows Tasks would be simple, but the date in the filename changes daily.  Therefore, I'd think I'd need to do one of the two things:
Use wildcards for the date in the filename in the script and make sure that they are the only files in the folder (that shows from other dates aren't in the same folder
The files being downloaded will always be downloaded on the same date as what's in the filename. I could instead use some type of variable which will look for files with the current date in the same format.  I'd prefer this so I could run it in a folder which included files from other dates, too, but not at all a dealbreaker

I'm trying to create something using AutoIT, but it's a bit above my current level.

Any ideas?  Thanks!
0
BzowK
Asked:
BzowK
  • 2
  • 2
3 Solutions
 
Bill PrewCommented:
Will there always be 5 files, or could that change?  And is the rest of the file name except for the date and part (1-5) always the same?

show_128k_12-01-2014_part005of05.mp3

~bp
0
 
Bill PrewCommented:
Here's a good starting point, based on what you described.  It should locate all the files with todays date in it and add them one at a time to the combined file.

@echo off
setlocal EnableDelayedExpansion

REM Make sure we are in the folder where the MP3 files are
pushd C:\Files

REM Get current date pieces (MM, DD, YYYY)
for /f "tokens=* skip=1" %%A in ('wmic os get LocalDateTime') do (
  if not defined LocalDateTime (
    set LocalDateTime=%%A
    set YYYY=!LocalDateTime:~0,4!
    set MM=!LocalDateTime:~4,2!
    set DD=!LocalDateTime:~6,2!
  )
)

REM Combine all matching files into a single MP3 file
for /f "tokens=*" %%A in ('dir /b /a-d /on "show_128k_%MM%-%DD%-%YYYY%_part*.mp3"') do (
  mp3wrap -a "show_128_%MM%-%DD%-%YYYY%_combined.mp3" "%%~A"
)

REM Return to original directory
popd

Open in new window

~bp
0
 
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
If the date format in the filename is :
    show_128k_12-01-2014_part001of05.mp3   where 12 is the month, 01 is the day then the following code combines the 5 files of the current date.
Then moves the file to the c:\destinationFolderName
Modify the source and destination location variables.

$sourceLocation = "c:\downloadedFiles"
$destinationLocation = "c:\destinationFolderName"
$date = $((get-date).Month.ToString() + "-" + (get-date).Day.ToString() + "-" + (get-date).Year.ToString())

$files = 1..5 | ForEach-Object { $($sourceLocation + "\show_128k_"+ $date + "_part00" + $_ + "of05.mp3")  }

$combinedFile = ($sourceLocation + "\show_128_" + ($date) + "_combined.mp3")

mp3wrap $combinedFile  $files[0] $files[1] $files[2] $files[3] $files[4] 

Move-Item $combinedFile $destinationLocation 

Open in new window

0
 
NVITCommented:
Here's a version that works on existing, different dated *_part*.mp3 files in the same folder. It would be useful if you miss processing the current day files, which the other solutions provide. I don't know  if MP3WRAP has an option to move the processed part files so I provided an option to MOVE those to the HoldDir folder. Remove the REM prefix on both lines to enable it.
@echo off
setlocal EnableDelayedExpansion

pushd C:\Files

REM Remove REM prefix below for MOVE feature
REM if not exist .\HoldDir\nul md HoldDir

REM Combine
for /f "tokens=*" %%a in ('dir /b /a-d /on "show_128k_*_part*.mp3"') do (call :DoIt %%a)
goto :eof

:DoIt
  set PartFile=%1
  set YYYY=%PartFile:~16,4%
  set MM=%PartFile:~10,2%
  set DD=%PartFile:~13,2%
  set FNTarget=show_128_%MM%-%DD%-%YYYY%_combined.mp3
  mp3wrap -a "%FNTarget%" "%PartFile%"
  REM Remove REM prefix below for MOVE feature
  REM move "%PartFile%" HoldDir
)
goto :eof

popd

Open in new window

0
 
NVITCommented:
Bzowk... Did any of this work for you❓
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now