我已经在这里找到了它的基本代码,并使用它来移动和重命名我知道文件名的文件。但是,现在我想移动一个文件,其中文件名是一个参数。
当我运行此代码时,它会用当前日期和时间重命名文件夹。如何重命名文件夹中的变量文件名?我添加了暂停,试图解决正在发生的问题。
Echo Off
SET SiteName=%~1
SET FileDate=%~2
SET File=%SiteName%%FileDate%
IF Not EXIST C:UsersAdministratorDocuments~Withdrawal_Report%File% GOTO DoNothing
copy C:UsersAdministratorDocuments~Withdrawal_Report%File% C:UsersAdministratorDocuments~Withdrawal_Report_Archive%File%
ren C:UsersAdministratorDocuments~Withdrawal_Report_Archive%File% %SiteName%-%date:~4,2%-%date:~7,2%-%date:~10,4%_@_%time:~0,2%h%time:~3,2%m%time:~6,2%s%.csv
ren C:UsersAdministratorDocuments~Withdrawal_Report_Archive%File% %SiteName%-%date:~4,2%-%date:~7,2%-%date:~10,4%_@_%time:~1,1%h%time:~3,2%m%time:~6,2%s%.csv
del C:UsersAdministratorDocuments~Withdrawal_Report%File%
pause
:DoNothing
Exit
尝试使用双引号,如下所示:
Echo Off
SET "SiteName=%~1"
SET "FileDate=%~2"
SET "File=%SiteName%%FileDate%"
IF Not EXIST "C:UsersAdministratorDocuments~Withdrawal_Report%File%" GOTO DoNothing
copy "C:UsersAdministratorDocuments~Withdrawal_Report%File%" "C:UsersAdministratorDocuments~Withdrawal_Report_Archive%File%"
ren "C:UsersAdministratorDocuments~Withdrawal_Report_Archive%File%" "%SiteName%-%date:~4,2%-%date:~7,2%-%date:~10,4%_@_%time:~0,2%h%time:~3,2%m%time:~6,2%s%.csv"
ren "C:UsersAdministratorDocuments~Withdrawal_Report_Archive%File%" "%SiteName%-%date:~4,2%-%date:~7,2%-%date:~10,4%_@_%time:~1,1%h%time:~3,2%m%time:~6,2%s%.csv"
del "C:UsersAdministratorDocuments~Withdrawal_Report%File%"
pause
:DoNothing
Exit
此外,据我所知,你试图对同一个文件重命名两次。以前用过吗?