标题: [文件操作] 批处理怎样重命名文件夹名称为IP地址+时间并上传到FTP服务器? [打印本页]
作者: 2210698653 时间: 2023-5-29 12:20 标题: 批处理怎样重命名文件夹名称为IP地址+时间并上传到FTP服务器?
重命名文件夹名称为IP地址+时间,重命名完成后上传到FTP服务器
作者: czjt1234 时间: 2023-5-29 13:49
IP地址是通过 ipconfig 命令获取?
作者: 2210698653 时间: 2023-5-29 14:10
回复 2# czjt1234
都可以,
作者: Batcher 时间: 2023-5-29 22:57
回复 1# 2210698653
打开一个CMD窗口,执行命令:- >1.txt echo %date%
- >>1.txt echo %time%
- >>1.txt ipconfig /all
复制代码
把生成的 1.txt 传上来我试试
如果需要上传文件,可以用阿里云盘或百度网盘。
如果需要上传截图,可以找个图床,例如:
http://bbs.bathome.net/thread-60985-1-1.html
作者: czjt1234 时间: 2023-5-31 15:32
- rem 另存为 ANSI 编码
- ' & cls & cscript.exe /nologo /e:vbscript "%~f0" %* & pause & exit
-
- folder = "D:\1"
- ftp = "ftp://a:Aa12345678@192.168.0.11"
-
- If wsh.Arguments.Count > 0 Then folder = wsh.Arguments(0)
- Set oShell = CreateObject("Shell.Application")
- Set oFolder = oShell.NameSpace(ftp)
- Set oFSO = CreateObject("Scripting.FileSystemObject")
- If Not oFSO.FolderExists(folder) Then wsh.Echo "未找到文件夹" : wsh.Quit()
- Set oWMI = GetObject("Winmgmts:\\.\Root\Cimv2")
- For Each i In oWMI.InstancesOf("Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'")
- s = i.IPAddress(0)
- Next
- s = s & "_" & F_D_T(Now(), "yyyymmdd_HHMMSS")
- s = oFSO.BuildPath(oFSO.GetParentFolderName(folder), s)
- wsh.Echo "原文件夹" & vbTab & folder
- wsh.Echo "重命名为" & vbTab & s
- wsh.Echo
- oFSO.MoveFolder folder, s
- Set oFolderItem = oShell.NameSpace(s).Self
- oFolder.CopyHere oFolderItem
-
- Function F_D_T(ByVal d, ByVal s)
- Dim oSWbemDateTime, oWMI, i, TimeZone
- Select Case UCase(s)
- Case "CIM_DATETIME"
- Set oSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
- oSWbemDateTime.SetVarDate d
- F_D_T = oSWbemDateTime.Value
- Case "INTERVAL FORMAT"
- Set oSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
- oSWbemDateTime.SetVarDate d
- oSWbemDateTime.IsInterval = True
- F_D_T = oSWbemDateTime.Value
- Case "FILENAME" 'UTC时间
- Set oSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
- oSWbemDateTime.SetVarDate d
- F_D_T = oSWbemDateTime.GetFileTime(False)
- Case "UNIX" '10位Unix时间戳,UTC时间
- Set oWMI = GetObject("Winmgmts:\\.\Root\Cimv2")
- For Each i In oWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem")
- TimeZone = i.CurrentTimeZone
- Next
- i = DateDiff("s", #1970-01-01 00:00:00#, d)
- F_D_T = i - TimeZone * 60
- Case Else
- s = Replace(s, "yyyy", Year(d), 1, -1, vbTextCompare)
- s = Replace(s, "yy", Right(Year(d), 2), 1, -1, vbTextCompare)
- s = Replace(s, "mm", Right("0" & Month(d), 2), 1, -1, vbBinaryCompare)
- s = Replace(s, "m", Month(d), 1, -1, vbBinaryCompare)
- s = Replace(s, "dd", Right("0" & Day(d), 2), 1, -1, vbTextCompare)
- s = Replace(s, "d", Day(d), 1, -1, vbTextCompare)
- s = Replace(s, "HH", Right("0" & Hour(d), 2), 1, -1, vbTextCompare)
- s = Replace(s, "H", Hour(d), 1, -1, vbTextCompare)
- s = Replace(s, "MM", Right("0" & Minute(d), 2), 1, -1, vbBinaryCompare)
- s = Replace(s, "M", Minute(d), 1, -1, vbBinaryCompare)
- s = Replace(s, "SS", Right("0" & Second(d), 2), 1, -1, vbTextCompare)
- s = Replace(s, "S", Second(d), 1, -1, vbTextCompare)
- F_D_T = s
- End Select
- End Function
复制代码
请自行修改ftp
win7x64测试通过,未考虑多网卡多ip的情况
支持文件夹拖放,支持文件夹绝对路径作为批处理命令行参数
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |