使用批处理脚本重命名动态文件

时间:2017-10-10 13:23:22

标签: windows batch-file

嗨我有多个文件有领带印章(随机)。

viewRender

我想使用批处理脚本重命名这些文件,请你帮忙。

PMPRO_Outbound_US05_20170927_114630.csv
PMPRO_Outbound_US05_20170928_115430.csv

PMPRO_Outbound_US05_20170927_114630.csv

请帮忙。

1 个答案:

答案 0 :(得分:0)

使用for循环:

Sub test2()
Dim sht As Worksheet, cell As Range, areaToTrim As Range, LastRow As Long, lstrow As Long, lrow As Long, sht1 As Worksheet, sht2 As Worksheet
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
Set sht = ThisWorkbook.Worksheets("JDE_Greece")
sht.Activate
Range("A1").EntireColumn.Insert
Sheets("JDE_Greece").Cells(1, 1) = "KEY"
Range("I1").EntireColumn.Insert
sht.Cells(1, 9) = "Quantity JDE (aggregated)"
Range("J1").EntireColumn.Insert
sht.Cells(1, 10) = "Item Code CDL (decomposed)"
Range("K1").EntireColumn.Insert
sht.Cells(1, 11) = "Item Code CDL"
Range("L1").EntireColumn.Insert
sht.Cells(1, 12) = "Quantity CDL (decomposed)"
Range("M1").EntireColumn.Insert
sht.Cells(1, 13) = "Quantity CDL"
Range("N1").EntireColumn.Insert
sht.Cells(1, 14) = "Overwrite (abs in vol)"
Range("O1").EntireColumn.Insert
sht.Cells(1, 15) = "Overwrite (abs in %)"
Range("P1").EntireColumn.Insert
sht.Cells(1, 16) = "Hit/Miss"
Set areaToTrim = Sheets("JDE_Greece").Range("G2:G" & LastRow)
For Each cell In areaToTrim
cell.Value = Trim(cell.Value)
Next cell
Columns("G:G").Select
Selection.NumberFormat = "@"
Range("J2:J" & LastRow).Value = "=IF(ISNA(VLOOKUP(G2,'mapping codes'!A:B,2,0)),G2,VLOOKUP(G2,'mapping codes'!A:B,2,0))"
Range("J2:J" & LastRow).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Selection.NumberFormat = "@"
Range("K2:K" & LastRow).Formula = "=IF(ISNA(VLOOKUP(""*""&J2&""*"",CDL_Greece!D:D,1,0)),J2,VLOOKUP(""*""&J2&""*"",CDL_Greece!D:D,1,0))"
Range("K2:K" & LastRow).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Selection.NumberFormat = "@"
Range("A2").Formula = "=K2&B2"
Range("A2").Copy Range("A3:A" & LastRow)
lstrow = Cells(Rows.Count, "A").End(xlUp).Row
Range("I2:I" & lstrow).Value = "=SUMIFS(H:H,G:G,G2,A:A,A2)"
Range("I2:I" & lstrow).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ActiveSheet.Range("A2:M" & LastRow).RemoveDuplicates Columns:=1, Header:=xlNo
lrow = Cells(Rows.Count, "A").End(xlUp).Row
Range("L2:L" & lrow).Value = "=VLOOKUP(A2,CDL_Greece!A:I,9,0)"
Range("L2:L" & lrow).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("M2:M" & lrow).Value = "=IF(ISNA(L2),VLOOKUP(VLOOKUP(""*""&G2&""*"",CDL_Greece!D:D,1,0)&B2,CDL_Greece!A:I,9,0),L2)"
Range("M2:M" & lrow).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("N2:N" & lrow).Value = "=ABS(M2-I2)"
Range("O2:O" & lrow).Value = "=ABS(I2-M2)/M2"
Range("O2:O" & lrow).Select
Selection.NumberFormat = "0.00%"
Range("P2:P" & lrow).Value = "=IF(M2=I2,1,0)"
Rows("1:1").Select
Selection.AutoFilter
Range("A1").Interior.Color = RGB(0, 255, 51)
Range("B1:H1").Interior.Color = RGB(255, 153, 102)
Range("I1:M1").Interior.ColorIndex = 37
Range("N1:P1").Interior.ColorIndex = 6
Set sht = ThisWorkbook.Worksheets("JDE_Greece")
Set sht1 = ThisWorkbook.Worksheets("Mismatches")
With sht
    lrow = .Cells(.Rows.Count, "A").End(xlUp).Row
    .Range("M1").AutoFilter Field:=13, Criteria1:="#N/A"
    .Range("A1:P" & lrow).SpecialCells(xlCellTypeVisible).Copy
End With
sht1.Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
Set sht2 = ThisWorkbook.Worksheets.Add
With sht2
    .Name = "Summary DRP"
    .Move After:=ThisWorkbook.Worksheets("Instructions")
End With
With sht
    .Range("M1").AutoFilter Field:=13, Criteria1:="<>#N/A"
    .Range("A1:P" & lrow).SpecialCells(xlCellTypeVisible).Copy
End With
sht2.Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
End Sub

如果您觉得它正在按照您的意图行事,请移除for /F %%i in ('dir /b *.csv') do echo mv %%i %%i_1 以执行实际的重命名。