renaming of files

hi,

i work for a radio stationand we have a piece of sofware that records files into mp3 and in the following convention 20110429190010.mp3 (so it gives the date and time)

i was wondering is there anyway to get a script to a) rename the file based on the time? and b) copy the file to somewhere else?

So for instance it sees this file with 1900 which corresponds to a show called part mix, could i get any file that shows 1900 to be renamed to partymix and copied to a location say c:\mp3 ?

Thanks as always
jonathanduane2010Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
Is the format of the current filename YYYYMMDDhhmmss ?

Do the time stamps vary on each file, and if so will a range check be needed, meaning that any files bewtween 1900 and 2000 should be associated with say "part mix" show?

It sounds like what you need could be done, but we would need a cross reference of the times that you want to copy to the show name to associate that with.

It would be helpful to see a larger sample of the filenames too.

~bp
jonathanduane2010Author Commented:
yes the software is called aircheck it records file every hour and then names them YYYYMMDDhhmmss

well if i could get a script and then could i just change it for every hour ? just swap out 1900 for 2000 and "partymix" for another associated show?
Patrick MatthewsCommented:
jonathanduane2010,

Some questions:

1) How much does your schedule vary?  For example, I would think it possible that your schedule is more or less the same Mon-Fri, but then I would expect that Sat and/or Sun could be quite different, thus making a rule such as "if it's 1900 it must be Party Mix" potentially problematic

2) All broadcast entities change their schedules over time.  How frequently does your station change its schedule?  And what about one-off specials?  Having some sort of scheduling database for the script to key off of is probably advisable.

Patrick
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Bill PrewIT / Software Engineering ConsultantCommented:
Also, is it possible to have more than one file with the same hhmm (hour/minute) value?  Either because there were multiple MP3's that hour, or from multiple days?  If so, how should these be handled?

~bp
jonathanduane2010Author Commented:
the point why i am trying to this is because we want to create files on our website for a "Listen Back Feature" and luckily enough the shows we are uploading only happen once a week.

So "partymix" is actually a 3 hour show from 1900-2200 so there shouldnt be any confliction and billprew no only one mp3 gets recorded per hour.
Bill PrewIT / Software Engineering ConsultantCommented:
Here's a quick BAT file approach.  Save this as a BAT file, and then run like this:

EE27026289.bat "1900" "partymix"

or

EE27026289.bat

in the first case the timestamp and showname will be gotten from the command line.  If they are not provided as in the second example then the script will prompt for them.

@echo off

REM Define source and destination folders
set BaseDir=c:\temp\base
set DestDir=c:\temp\dest

REM Get timestamp to process from command line, or prompt if none provided
if "%~1"=="" (
  set /p "HHMM=Please specify timestamp for file to process (HHMM): "
) else (
  set HHMM=%~1
)
if "%HHMM%"=="" (
  echo ERROR: No file timestamp specified.
  exit /b
)

REM Get showname from command line, or prompt if none provided
if "%~2"=="" (
  set /p "SHOW=Please specify showname to rename file to: "
) else (
  set SHOW=%~2
)
if "%SHOW%"=="" (
  echo ERROR: No showname specified.
  exit /b
)

REM Find files for this HHMM and copy and rename
for %%A in ("%BaseDir%\????????%HHMM%??.mp3") do (
  ECHO copy "%%~A" "%DestDir%\%SHOW%.mp3"
  ECHO ren "%%~A" "%SHOW%.mp3"
)

Open in new window

~bp
Bill PrewIT / Software Engineering ConsultantCommented:
Also, note the "ECHO" in the front of these two line:

  ECHO copy "%%~A" "%DestDir%\%SHOW%.mp3"
  ECHO ren "%%~A" "%SHOW%.mp3"


for testing when you run the script this way, it won't actually rename of copy the files, it will just display the commands that would be executed to the screen.  This is very helpful when debugging the script, and avoids renaming the files incorrectly if there is a bug in the code.

When you are satisfied that the script should do what you need based on the output of those commands to the screen, remove the word ECHO from the front of those two lines, and run for real.

~bp
jonathanduane2010Author Commented:
thanks a mill for this guys is there anyway i could run it with no interaction as i will probably need to run them as scheduled tasks?
Bill PrewIT / Software Engineering ConsultantCommented:
In the case of running as a scheduled job, how will the timestamp and showname be specified?

~bp
jonathanduane2010Author Commented:
the showname will still be the same just there wiont be anybody around to run the bat file at 1900 every friday?
Bill PrewIT / Software Engineering ConsultantCommented:
So are you saying you just want the script to ALWAYS use 1900 and "partymix", as in:

@echo off

REM Define source and destination folders
set BaseDir=c:\temp\base
set DestDir=c:\temp\dest
set HHMM=1900
set SHOW=partymix

REM Fine files for this HHMM and copy and rename
for %%A in ("%BaseDir%\????????%HHMM%??.mp3") do (
  ECHO copy "%%~A" "%DestDir%\%SHOW%.mp3"
  ECHO ren "%%~A" "%SHOW%.mp3"
)

Open in new window

~bp
jonathanduane2010Author Commented:
yes thats brilliant!

do i still have to take out the echos?
Bill PrewIT / Software Engineering ConsultantCommented:
Yes, once you try it from the command line and verify that it is doing the right things with the right files, remove the ECHOs.

~bp

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.