Here is a script that was written for me that does the following:
For archival purposes on a feature film I was working on.
- saves all media from a specified drive (specified in the beginning of the script) to the project folder.
- you can add exceptions to the beginning of the script for file types you want to ignore.
- files that are being copied to the project directory that already exist get renamed with a (1) or (2), etc at the end of the filename.
This is great if you've been working on a large project and have files from all over the place and want to save off the whole project to a new drive and make sure all the media follows it. It also relinks the media after copying it to the new location.
enjoy.
using System;
using System.IO;
using System.Text;
using System.Collections;
using Sony.Vegas;
public class EntryPoint
{
String sourceRoot = "S:\\";
String[] excludeTypes = new String[]
{
".avi",
".mov",
".mpeg",
".veg"
};
bool relinkMedia = true;
Vegas myVegas;
public void FromVegas(Vegas vegas)
{
myVegas = vegas;
Go(null, null);
}
public void Go(Object sender, EventArgs args)
{
String projectDir = Path.GetDirectoryName(myVegas.Project.FilePath);
ArrayList sourceMedia = new ArrayList();
foreach (Media media in myVegas.Project.MediaPool)
{
if (media.IsOffline()) continue;
if (media.IsGenerated()) continue;
if (media.IsImageSequence()) continue;
if (media.IsSubclip()) continue;
String sourcePath = media.FilePath;
String mediaRoot = Path.GetPathRoot(sourcePath);
if (mediaRoot == sourceRoot)
{
String sourceExt = Path.GetExtension(sourcePath);
bool filterIt = false;
foreach (String ext in excludeTypes)
{
if (sourceExt == ext)
{
filterIt = true;
break;
}
}
if (filterIt) continue;
sourceMedia.Add(media);
}
}
foreach (Media media in sourceMedia)
{
String sourcePath = media.FilePath;
String targetPath = Path.Combine(projectDir, Path.GetFileName(sourcePath));
int renamedFileIndex = 0;
while (File.Exists(targetPath))
{
targetPath = Path.Combine(projectDir,
String.Format("{0} ({1}){2}",
Path.GetFileNameWithoutExtension(sourcePath),
++renamedFileIndex,
Path.GetExtension(sourcePath)));
}
File.Copy(sourcePath, targetPath);
if (relinkMedia)
{
media.ReplaceWith(new Media(targetPath));
myVegas.Project.MediaPool.Remove(sourcePath);
}
}
}
}
For archival purposes on a feature film I was working on.
- saves all media from a specified drive (specified in the beginning of the script) to the project folder.
- you can add exceptions to the beginning of the script for file types you want to ignore.
- files that are being copied to the project directory that already exist get renamed with a (1) or (2), etc at the end of the filename.
This is great if you've been working on a large project and have files from all over the place and want to save off the whole project to a new drive and make sure all the media follows it. It also relinks the media after copying it to the new location.
enjoy.
using System;
using System.IO;
using System.Text;
using System.Collections;
using Sony.Vegas;
public class EntryPoint
{
String sourceRoot = "S:\\";
String[] excludeTypes = new String[]
{
".avi",
".mov",
".mpeg",
".veg"
};
bool relinkMedia = true;
Vegas myVegas;
public void FromVegas(Vegas vegas)
{
myVegas = vegas;
Go(null, null);
}
public void Go(Object sender, EventArgs args)
{
String projectDir = Path.GetDirectoryName(myVegas.Project.FilePath);
ArrayList sourceMedia = new ArrayList();
foreach (Media media in myVegas.Project.MediaPool)
{
if (media.IsOffline()) continue;
if (media.IsGenerated()) continue;
if (media.IsImageSequence()) continue;
if (media.IsSubclip()) continue;
String sourcePath = media.FilePath;
String mediaRoot = Path.GetPathRoot(sourcePath);
if (mediaRoot == sourceRoot)
{
String sourceExt = Path.GetExtension(sourcePath);
bool filterIt = false;
foreach (String ext in excludeTypes)
{
if (sourceExt == ext)
{
filterIt = true;
break;
}
}
if (filterIt) continue;
sourceMedia.Add(media);
}
}
foreach (Media media in sourceMedia)
{
String sourcePath = media.FilePath;
String targetPath = Path.Combine(projectDir, Path.GetFileName(sourcePath));
int renamedFileIndex = 0;
while (File.Exists(targetPath))
{
targetPath = Path.Combine(projectDir,
String.Format("{0} ({1}){2}",
Path.GetFileNameWithoutExtension(sourcePath),
++renamedFileIndex,
Path.GetExtension(sourcePath)));
}
File.Copy(sourcePath, targetPath);
if (relinkMedia)
{
media.ReplaceWith(new Media(targetPath));
myVegas.Project.MediaPool.Remove(sourcePath);
}
}
}
}