Improve company productivity with a Business Account.Sign Up

x
?
Solved

Script to Run Command Using Filenames With Wildcards

Posted on 2014-12-20
5
Medium Priority
?
556 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 61

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 61

Assisted Solution

by:Bill Prew
Bill Prew earned 668 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 664 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 26

Accepted Solution

by:
NVIT earned 668 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 26

Expert Comment

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Welcome to 2018! Exciting things lie ahead in the world of tech. To start things off, we compiled great member articles on how to stay safe, ways to learn, and much more! Read on to start your new year right.
WAP (Web Application Proxy) provides reverse proxy functionality for web applications in the corporate network which allows users on most devices to access internal web applications from external networks.
Loops Section Overview
Did you know PowerShell can save you time with SaaS platforms? Simply leverage RESTfulAPIs to build your own PowerShell modules. These will kill repetitive tickets and tabs, using the command Invoke-RestMethod. Tune into this webinar to learn how…

595 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