Renaming media files on the timeline

douglas_clark wrote on 2/18/2007, 7:37 PM
I would like to rename media files for each event on the timeline.
Since there is no "Rename" function in jscript, I assume I need to use the System.IO.File.Move (SourceFileName, DestFileName) method.

When I try this, I get "Error: The process cannot access the file because it is being used by another process."

Do I have to remove the file from the timeline before it can be renamed? Can anyone help me with this?

Home-built ASUS PRIME Z270-A, i7-7700K, 32GB; Win 10 Pro x64 (22H2);
- Intel HD Graphics 630 (built-in); no video card; ViewSonic VP3268-4K display via HDMI
- C: Samsung SSD 970 EVO 1TB; + several 10TB HDDs
- Røde AI-1 via Røde AI-1 ASIO driver;

Comments

douglas_clark wrote on 2/19/2007, 5:35 AM
Ahaa...someone had set my media files to readonly! Who did that? ;-( Me.

Renaming media seems to work fine with this sequence. I am adding the DATE & TIME to the front of the filename, in the format YYMMDD_HHMMSS_. This is in a loop on events on a track, or media in the MediaPool.

origFilePath = origMedia.FilePath;
origFileDir = Path.GetDirectoryName(origFilePath);
origFileName = Path.GetFileName(origFilePath);
origDateTime = File.GetLastWriteTime(origFilePath);
newFileName = origDateTime.ToString("yyMMdd_HHmmss_") + origFileName;
newFilePath = Path.Combine(origFileDir,newFileName);
File.Move(origFilePath, newFilePath);
origMedia.ReplaceWith(new Media(newFilePath) );

Is there a better way to do this?

There should probably be some checking that the new filename doesn't already exist, and is valid, etc.

Note that this operation cannot be undone, (ie. undo run script), because the original media names will no longer exist.

Home-built ASUS PRIME Z270-A, i7-7700K, 32GB; Win 10 Pro x64 (22H2);
- Intel HD Graphics 630 (built-in); no video card; ViewSonic VP3268-4K display via HDMI
- C: Samsung SSD 970 EVO 1TB; + several 10TB HDDs
- Røde AI-1 via Røde AI-1 ASIO driver;