我需要将今天的日期paymentpagecalls20200128.txt
和WithdrawalConfirm20200128.txt
重命名为paymentpagecalls20200129_*time*.txt
,并在每 8 小时或可能的情况下将 12:00am/6:00am/10:00 PM 重命名为WithdrawalConfirm20200129_*time*.txt
。
我有这个代码来获得我的时间(只是将其复制到我的一些搜索中(
set "destination=C:UsersJBP-AdminDesktopPugadForback_UPDestination"
set day=0
echo >"%temp%%~n0.vbs" s=DateAdd("d",%day%,now) : d=weekday(s)
echo>>"%temp%%~n0.vbs" WScript.Echo year(s)^& right(100+month(s),2)^& right(100+day(s),2)
for /f %%a in ('cscript /nologo "%temp%%~n0.vbs"') do set "result=%%a"
del "%temp%%~n0.vbs"
set "YYYY=%result:~0,4%"
set "MM=%result:~4,2%"
set "DD=%result:~6,2%"
set "result=%yyyy%%mm%%dd%"
echo %result%
for /r "C:UsersJBP-AdminDesktopPugadFor Rename" %%G in (*%result%.txt) do (
ren "%%~fG" "C:UsersJBP-AdminDesktopPugadFor Rename"
if exist "C:UsersJBP-AdminDesktopPugadFor Rename%%~nxG" (
echo File "%%~fG" renamed successfully.
) else (
echo File "%%~fG" renamed failed.
)
)
pause
如何插入零件以检查时间然后重命名?
分解正在发生的事情
- 从所述目录中检索与给定条件匹配的所有.txt文件
- 我们解析文件名并提取现有日期并附加新日期
- 重命名文件
这个".exe"的输出可以在任务中调度 根据给定条件以给定的时间间隔执行调度程序。
转到任务计划程序>操作>创建基本任务>设置触发器、操作>完成
using System;
using System.IO;
using System.Linq;
namespace Test
{
public class Program
{
static void Main(string[] args)
{
string FolderPath = @"C:UsersJohnDocuments";
DirectoryInfo di = new DirectoryInfo(FolderPath);
var files = di.EnumerateFiles("*.txt")
.Where(s => s.Name.Contains("Withdrawal")
|| s.Name.Contains("payment")).ToList();
var Currentfile1 = files[0].FullName;
var Currentfile2 = files[1].FullName;
//Parsing files
var Newfile1 = Currentfile1.Substring(0, Currentfile1.Length - 2);
var Newfile2 = Currentfile2.Substring(0, Currentfile2.Length - 2);
// Append new date
Newfile1 = Newfile1 + DateTime.Now.ToString("yyyyMMdd") + ".txt";
Newfile2 = Newfile2 + DateTime.Now.ToString("yyyyMMdd") + ".txt";
//Rename
File.Move(Currentfile1, Newfile1);
File.Move(Currentfile2, Newfile2);
}
}
}