Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Script to Run Command Using Filenames With Wildcards

Posted on 2014-12-20
5
Medium Priority
?
544 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 58

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 58

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 25

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 25

Expert Comment

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

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

604 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