我正在将数据提取到某个文本文件中,但首先我希望我的脚本检查文件是否存在,然后在某个文件夹中创建副本。如果它仍然存在于同一个文件夹中,请保存它,但附加值 _1 或 _2 ...取决于最后一个文件的值。
这是我目前的脚本,
if (-e "/tmp/POP_Airtime_Week1.txt"){
copy("/tmp/POP_Airtime_Week1.txt","/tmp/POP") || die "cannot copy file";
# If the file exists create a copy in /tmp/POP
#################################
# IF FILE EXISTS IN /tmp/POP copy the file but rename it to
# POP_Airtime_Week1_1.txt then increase the numbers each time
# the script is run and a new copy needs to be created.
##################################
unlink ("/tmp/POP_Airtime_Week1.txt");
}
如果/tmp/POP/POP_Airtime_Week1.txt
存在,则将其复制但另存为/tmp/POP/POP_Airtime_Week1_1.txt
. 下次我运行脚本并/tmp/POP/POP_Airtime_Week1.txt
存在时,将其复制并另存为/tmp/POP/POP_Airtime_Week1_2.txt
等...
我怎样才能做到这一点?