I am using Audacity's Chains scripting function to batch-convert and edit many large, uncompressed .WAV files at once to a much smaller .OGG format. I end up with a folder structure like the following:
我正在使用Audacity的Chains脚本函数批量转换和编辑许多大型未压缩的.WAV文件,同时使用更小的.OGG格式。我最终得到了如下文件夹结构:
f:/sound-recordings:
-- rec1.wav
-- rec2.wav
-- rec3.wav
-- rec4.wav
-- rec5.wav
f:/sound-recordings/cleaned:
-- rec1.ogg
-- rec2.ogg
-- rec3.ogg
Some of the source .WAV files are corrupted (note rec4.wav and rec5.wav in above example), and Audacity will not convert them (at least through the chains function). This creates a problem, as it can become very tedious to compare the two folders, and delete only the .WAV files which were successfully converted to .OGG.
一些源.WAV文件已损坏(请注意上面示例中的rec4.wav和rec5.wav),Audacity将不会转换它们(至少通过链接功能)。这会产生问题,因为比较两个文件夹会变得非常繁琐,并且只删除已成功转换为.OGG的.WAV文件。
In the example above, "rec1.wav", "rec2.wav", and "rec3.wav" should be deleted, while "rec4.wav" and "rec5.wav" are untouched, since they weren't converted.
在上面的示例中,应删除“rec1.wav”,“rec2.wav”和“rec3.wav”,而“rec4.wav”和“rec5.wav”不受影响,因为它们未被转换。
I need a script (batch or python preferred) to delete any .WAV files from the main folder, that have identically named .OGG files located in the "cleaned" folder, leaving other .WAV files untouched.
我需要一个脚本(批处理或python首选)来删除主文件夹中的任何.WAV文件,这些文件具有位于“已清理”文件夹中的同名.OGG文件,其他.WAV文件保持不变。
2 个解决方案
#1
2
@echo off
for %%I in (f:\sound-recordings\*.wav) do (
if exist f:\sound-recordings\cleaned\%%~nI.ogg del %%I
)
#2
0
You can create a list of the elements in the clean directory, using split
to strip off the extension and then iterator through the dirty directory checking if it is in
clean.
您可以在clean目录中创建元素列表,使用split来剥离扩展,然后通过脏目录检查迭代器是否处于干净状态。
Basic python pseudo-code would look like:
基本的python伪代码看起来像:
clean = [filename.split('.')[0] for filename in clean_directory]
delete = [filename for filename in dirty_directory if filename.split('.')[0] in clean]
for filename in delete:
os.remove(filename)
#1
2
@echo off
for %%I in (f:\sound-recordings\*.wav) do (
if exist f:\sound-recordings\cleaned\%%~nI.ogg del %%I
)
#2
0
You can create a list of the elements in the clean directory, using split
to strip off the extension and then iterator through the dirty directory checking if it is in
clean.
您可以在clean目录中创建元素列表,使用split来剥离扩展,然后通过脏目录检查迭代器是否处于干净状态。
Basic python pseudo-code would look like:
基本的python伪代码看起来像:
clean = [filename.split('.')[0] for filename in clean_directory]
delete = [filename for filename in dirty_directory if filename.split('.')[0] in clean]
for filename in delete:
os.remove(filename)