Solved

Script to Run Command Using Filenames With Wildcards

Posted on 2014-12-20
5
527 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 53

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 53

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 19

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 24

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 24

Expert Comment

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

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
A procedure for exporting installed hotfix details of remote computers using powershell
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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