[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

renaming of files

Posted on 2011-05-09
13
Medium Priority
?
245 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:jonathanduane2010
  • 7
  • 5
13 Comments
 
LVL 59

Expert Comment

by:Bill Prew
ID: 35720497
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
0
 

Author Comment

by:jonathanduane2010
ID: 35720596
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?
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 35720639
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 59

Expert Comment

by:Bill Prew
ID: 35720719
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
0
 

Author Comment

by:jonathanduane2010
ID: 35720763
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.
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 35720884
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
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 35720907
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
0
 

Author Comment

by:jonathanduane2010
ID: 35721019
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?
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 35721126
In the case of running as a scheduled job, how will the timestamp and showname be specified?

~bp
0
 

Author Comment

by:jonathanduane2010
ID: 35721200
the showname will still be the same just there wiont be anybody around to run the bat file at 1900 every friday?
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 35721363
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
0
 

Author Comment

by:jonathanduane2010
ID: 35721400
yes thats brilliant!

do i still have to take out the echos?
0
 
LVL 59

Accepted Solution

by:
Bill Prew earned 1000 total points
ID: 35721412
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
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Make the most of your online learning experience.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

834 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