Solved

Script to Run Command Using Filenames With Wildcards

Posted on 2014-12-20
5
397 Views
Last Modified: 2015-01-05
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
Comment
Question by:BzowK
  • 2
  • 2
5 Comments
 
LVL 51

Expert Comment

by:Bill Prew
ID: 40510907
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
 
LVL 51

Assisted Solution

by:Bill Prew
Bill Prew earned 167 total points
ID: 40510930
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
 
LVL 18

Assisted Solution

by:Raheman M. Abdul
Raheman M. Abdul earned 166 total points
ID: 40511100
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
 
LVL 23

Accepted Solution

by:
NVIT earned 167 total points
ID: 40511248
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
 
LVL 23

Expert Comment

by:NVIT
ID: 40518099
Bzowk... Did any of this work for you❓
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now