我有7个文件。在bat文件中,我想检查文件名,然后检查当前日期的raname。就像一个SELECT *
INTO tbl_Test
FROM
(SELECT
qry_BomLevel1_PartNo.Type, qry_BomLevel1_PartNo.PartNo,
qry_BomLevel1_Desc.Description, qry_BomLevel1_Rev.Revision,
qry_BomLevel1_PartNo.Qty, qry_BomLevel1_Comment.Comment
FROM
qry_BomLevel1_PartNo
LEFT JOIN
((qry_BomLevel1_Desc
LEFT JOIN
qry_BomLevel1_Rev ON (qry_BomLevel1_Desc.XRefConfigurationID = qry_BomLevel1_Rev.XRefConfigurationID)
AND (qry_BomLevel1_Desc.ChildRevNr = qry_BomLevel1_Rev.ChildRevNr)
AND (qry_BomLevel1_Desc.ChildID = qry_BomLevel1_Rev.ChildID))
LEFT JOIN
qry_BomLevel1_Comment ON (qry_BomLevel1_Rev.XRefConfigurationID = qry_BomLevel1_Comment.XRefConfigurationID)
AND (qry_BomLevel1_Rev.ChildRevNr = qry_BomLevel1_Comment.ChildRevNr)
AND (qry_BomLevel1_Rev.ChildID = qry_BomLevel1_Comment.ChildID))
ON (qry_BomLevel1_PartNo.XRefConfigurationID = qry_BomLevel1_Desc.XRefConfigurationID)
AND (qry_BomLevel1_PartNo.ChildRevNr = qry_BomLevel1_Desc.ChildRevNr)
AND (qry_BomLevel1_PartNo.ChildID = qry_BomLevel1_Desc.ChildID)
UNION ALL
SELECT
qry_BomLevel2_PartNo.Type, qry_BomLevel2_PartNo.PartNo,
qry_BomLevel2_Desc.Description, qry_BomLevel2_Rev.Revision,
qry_BomLevel2_PartNo.Qty, qry_BomLevel2_Comment.Comment
FROM
qry_BomLevel2_PartNo
LEFT JOIN
((qry_BomLevel2_Desc
LEFT JOIN
qry_BomLevel2_Rev ON (qry_BomLevel2_Desc.ChildID = qry_BomLevel2_Rev.ChildID)
AND (qry_BomLevel2_Desc.ChildRevNr = qry_BomLevel2_Rev.ChildRevNr)
AND (qry_BomLevel2_Desc.XRefConfigurationID = qry_BomLevel2_Rev.XRefConfigurationID))
LEFT JOIN
qry_BomLevel2_Comment ON (qry_BomLevel2_Rev.ChildID = qry_BomLevel2_Comment.ChildID)
AND (qry_BomLevel2_Rev.ChildRevNr = qry_BomLevel2_Comment.ChildRevNr)
AND (qry_BomLevel2_Rev.XRefConfigurationID = qry_BomLevel2_Comment.XRefConfigurationID))
ON (qry_BomLevel2_PartNo.XRefConfigurationID = qry_BomLevel2_Desc.XRefConfigurationID)
AND (qry_BomLevel2_PartNo.ChildRevNr = qry_BomLevel2_Desc.ChildRevNr)
AND (qry_BomLevel2_PartNo.ChildID = qry_BomLevel2_Desc.ChildID))
/ if
条件
示例
else
重命名为abc.txt
(xyzyyyymmdd_1.txt) xyz20190715_1.txt
重命名为pqr.txt
(defyyyymmdd_1.txt) 我是批处理文件的新手,并尝试过此操作:
def20190715_1.txt
预期产量
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename
"abc.txt" %%e-%%f-%%g.dat
重命名为abc.txt
xyz20190715_1.txt
重命名为pqr.txt
答案 0 :(得分:1)
如果问题是要获取实际日期,那么对于今天的日期,最好执行以下操作:
for /f %%a in ('wmic path win32_LocalTime Get Day^,Month^,Year /value') do >nul set "%%a"
set Month=00%Month%
set Month=%Month:~-2%
set Day=00%Day%
set Day=%Day:~-2%
set today=%Year%%Month%%Day%
否则,您需要提出一个真实的问题,该问题以“我该怎么办”开头
答案 1 :(得分:1)
“循环浏览文件”类似于
for %%I in (*.txt) do echo %%I
这就是为什么我问如何知道替代物的原因。
由于似乎没有规则,您必须分别重命名每个文件(仅7个文件就不会有太大的危害,但是如果多了一百个矿石,就会使您发疯。)我还使用了另一种方式来获取日期字符串(与语言环境设置无关):
@echo off
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set "datetime=%%I"
set "datetime=%datetime:~0,8%"
ren "contract.txt" "DNSM%datetime%_x.DAT"
ren "security.DAT"" "NSM%datetime%_x.DAT"
ren "Participant.txt" "PM%datetime%_x.DAT"
ren "SCRIP_master.txt" "BSM%datetime%_x.DAT"
ren "DPRxxxx" "BSE_YearlyHL%datetime%_x.DAT"
ren "fo_participant.txt" "DPM%datetime%_x.DAT"
ren "spd_ contract.txt" "SCM%datetime%_x.DAT"
答案 2 :(得分:1)
auth: {
'user': 'API key',
'pass': 'mypassword'
}