我使用 iSpy 软件录制音频,并已将其设置为将录音保存到文件夹中。问题是它根本没有组织,所以我将数千条录音放在一个文件夹中。
我的目标是建立一个按日期组织的文件夹结构,并在一天结束时移动所有已创建/修改的文件(注意:创建日期与修改日期不同,因此如果脚本有差异,我希望两者都可用。)。
文件夹位置为:M:\Security Software\iSpy\audio\VHCEX
这是一个示例文件名:1_2016-04-19_14-06-02.mp3
或 1_YYYY-MM-DD_HH-MM-SS.mp3
在我的研究中,我遇到了以下脚本[来源]
@echo off
for /d %%i in (*) do (
cd %%i
call :doMove
cd ..
)
echo Really Done
goto eof:
pause
:doMove
echo Moving files... Please wait...
for /F "tokens=1-3,4* delims=-_" %%a in ('dir /b *.avi') do (
title Processing %%b-%%c-%%d_%%e
if not exist ".\%%b\%%c\%%d" (
mkdir ".\%%b\%%c\%%d"
echo New Date: \%%b\%%c\%%d
)
if exist "%%a_%%b-%%c-%%d_%%e" move "%%a_%%b-%%c-%%d_%%e" ".\%%b\%%c\%%d\%%e"
if exist "%%a_%%b_%%c-%%d-%%e" move "%%a_%%b_%%c-%%d-%%e" ".\%%b\%%c\%%d\%%e"
)
for /F "tokens=1-3,4* delims=-_" %%a in ('dir /b *.mp4') do (
title Processing %%b-%%c-%%d_%%e
if not exist ".\%%b\%%c\%%d" mkdir ".\%%b\%%c\%%d"
if exist "%%a_%%b-%%c-%%d_%%e" move "%%a_%%b-%%c-%%d_%%e" ".\%%b\%%c\%%d\%%e"
if exist "%%a_%%b_%%c-%%d-%%e" move "%%a_%%b_%%c-%%d-%%e" ".\%%b\%%c\%%d\%%e"
)
echo Moving Thumbs
for /F "tokens=1-3,4* delims=-_" %%a in ('dir /b thumbs\*.jpg') do (
title Processing %%b-%%c-%%d_%%e
if exist "thumbs\%%a_%%b-%%c-%%d_%%e" move "thumbs\%%a_%%b-%%c-%%d_%%e" ".\%%b\%%c\%%d\%%e"
if exist "thumbs\%%a_%%b_%%c-%%d-%%e" move "thumbs\%%a_%%b_%%c-%%d-%%e" ".\%%b\%%c\%%d\%%e"
)
title Done.
:EOF
我还发现了一个 Perl 脚本[来源]
#!/usr/bin/perl -w
use strict;
use File::stat;
use File::Copy;
use POSIX;
use Mail::Sendmail;
use Date::Calc qw(:all);
my $oldest_week = 4;
my $delete_week = 1;
my $move_count = 0;
my $delete_count = 0;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
$year += 1900;
$mon += 1;
my ($current_week,$current_year) = Week_of_Year($year, $mon, $mday);
my @folders = ("D:/iSpy/video/Front Door",
"D:/iSpy/video/Front Path",
"D:/iSpy/video/Garden",
"D:/iSpy/video/Lounge",
"D:/iSpy/video/Patio",
"D:/iSpy/video/Shed");
foreach (@folders)
{
my $viddir=$_;
print "$viddir\n\n";
opendir("curdir",$viddir)||die("Cannot open Directory!");
my @names=readdir("curdir");
foreach (@names)
{
my $name=$_;
my $source = $viddir."/".$name;
my $upname=uc($name);
my $pos_avi=index($upname,".AVI");
my $pos_mp4=index($upname,".MP4");
if ($pos_avi > 0 or $pos_mp4 > 0)
{
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime (stat($source)->mtime);
$year += 1900;
$mon += 1;
my ($week,$year) = Week_of_Year($year, $mon, $mday);
print "file $source was updated on $year $mon $mday - that was week $week - ";
my $target="$viddir/$week";
print "Move to folder $viddir/$week\n";
move($source,$target);
$move_count ++;
}
}
}
if ($oldest_week >= $current_week) {
$delete_week = 52 + $current_week - $oldest_week;
} else {
$delete_week = $current_week - $oldest_week;
}
@folders = ("D:/iSpy/video/Front Door/$delete_week",
"D:/iSpy/video/Front Path/$delete_week",
"D:/iSpy/video/Garden/$delete_week",
"D:/iSpy/video/Lounge/$delete_week",
"D:/iSpy/video/Patio/$delete_week",
"D:/iSpy/video/Shed/$delete_week");
foreach (@folders)
{
my $delete_dir=$_;
opendir("curdir",$delete_dir)||die("Cannot open Directory!");
my @names=readdir("curdir");
foreach (@names) {
my $name=$_;
my $target = "$delete_dir/$name";
my $upname=uc($name);
my $pos_avi=index($upname,".AVI");
my $pos_mp4=index($upname,".MP4");
if ($pos_avi > 0 or $pos_mp4 > 0)
{
print "file to delete is $target\n";
unlink $target;
$delete_count ++;
}
}
}
my $mail_body = "$move_count moved";
if ($delete_count > 0) {
$mail_body = $mail_body . ", $delete_count deleted from folder $delete_week\n";
}
print "$mail_body\n";
my %mail = (
To => '[email protected]',
From => '[email protected]',
Subject => 'Daily iSpy Recordings Move / Delete',
Message => $mail_body,
'content-type' => 'text/html; charset="iso-8859-1"',
'X-Mailer' => "Mail::Sendmail version $Mail::Sendmail::VERSION",
);
$mail{Smtp} = 'smtp.anywhere.com';
if (sendmail %mail) { print "Mail sent OK.\n\n" }
else { print "Error sending mail: $Mail::Sendmail::error \n" }
两者都需要进行调整以适合我的具体情况,但我不确定如何编辑其中任何一个。