Archive

Posts Tagged ‘VBA’

DIR命令无法获得精确到秒的问题

July 5th, 2021 No comments

DIR命令无法获得精确到秒的问题

方法一,dir命令只能到分钟,如果需要到秒,建议改用forfiles命令

REM "delims=" is required to avoid stripping AM/PM
for /f "delims=" %%i in ('"forfiles /p C:\Users\limc /m *.bat /c "cmd /c echo @fdate @ftime" "') do set modif_time=%%i
echo %modif_time%

参考
https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/cc753551(v=ws.11)?redirectedfrom=MSDN

方法二,用VBS的FileSystemObject方式解决

@set @n=0/*&echo off
dir /a-d/s/b|Cscript -nologo -e:jscript "%~f0" > 1.txt
pause&exit /b */
var fso=new ActiveXObject('scripting.FileSystemObject');
while(!WSH.StdIn.AtEndOfStream)
{
file=fso.GetFile(WSH.StdIn.ReadLine());
t=new Date(file.DateCreated);
t1 = t.getFullYear() + "-" + (t.getMonth() + 1) + "-" + t.getDate() + " " + t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds();
WSH.Echo(file + "\t" + t1);
}
Categories: 零敲碎打 Tags: , ,

[VBA]Base64编码和Base64解码

March 26th, 2019 No comments

VBA实现Base64编码和Base64解码,用于处理加密的URL非常方便。

VBA Base64 编码/加密函数:

'VBA Base64 编码/加密函数:
Function Base64Encode(StrA As String) As String                                  'Base64 编码
    On Error GoTo over                                                          '排错
    Dim buf() As Byte, length As Long, mods As Long
    Dim Str() As Byte
    Dim i, kk As Integer
    kk = Len(StrA) - 1
    ReDim Str(kk)
    For i = 0 To kk
        Str(i) = Asc(Mid(StrA, i + 1, 1))
    Next i
    Const B64_CHAR_DICT = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
    mods = (UBound(Str) + 1) Mod 3   '除以3的余数
    length = UBound(Str) + 1 - mods
    ReDim buf(length / 3 * 4 + IIf(mods <> 0, 4, 0) - 1)
    For i = 0 To length - 1 Step 3
        buf(i / 3 * 4) = (Str(i) And &HFC) / &H4
        buf(i / 3 * 4 + 1) = (Str(i) And &H3) * &H10 + (Str(i + 1) And &HF0) / &H10
        buf(i / 3 * 4 + 2) = (Str(i + 1) And &HF) * &H4 + (Str(i + 2) And &HC0) / &H40
        buf(i / 3 * 4 + 3) = Str(i + 2) And &H3F
    Next
    If mods = 1 Then
        buf(length / 3 * 4) = (Str(length) And &HFC) / &H4
        buf(length / 3 * 4 + 1) = (Str(length) And &H3) * &H10
        buf(length / 3 * 4 + 2) = 64
        buf(length / 3 * 4 + 3) = 64
    ElseIf mods = 2 Then
        buf(length / 3 * 4) = (Str(length) And &HFC) / &H4
        buf(length / 3 * 4 + 1) = (Str(length) And &H3) * &H10 + (Str(length + 1) And &HF0) / &H10
        buf(length / 3 * 4 + 2) = (Str(length + 1) And &HF) * &H4
        buf(length / 3 * 4 + 3) = 64
    End If
    For i = 0 To UBound(buf)
        Base64Encode = Base64Encode + Mid(B64_CHAR_DICT, buf(i) + 1, 1)
    Next
over:
End Function

Read more…

Categories: 零敲碎打 Tags: , ,