我想知道是否有人可以帮我编辑这个VBA脚本,这样它不仅可以移动文件(顺便说一下这部分是完整的),但是它还会在文件名的前面附加一个0(这部分没有已经开始了。
因此,如果原始文件名是123456789.tif,那么结果将是0123456789.tif。
谢谢!
Sub MoveIfFilelength()
'This script moves files from a source directory to a final directory based on the number of characters in the filename (e.g., 14, as below)
Dim srcDir As String
Dim dstDir As String
Dim f As String
srcDir = "S:\\" 'Input source directory
dstDir = "S:\\" 'Input destination directory
f = Dir(srcDir)
Do While f <> ""
If Len(f) = 13 Then Name srcDir & "\" & f As dstDir & "\" & f 'Input filename length
f = Dir()
Loop
End Sub
答案 0 :(得分:2)
Name .. As
是移动操作,在语义上已经是重命名,因此请将新名称指定为"\0" & f
:
If Len(f) = 13 Then Name srcDir & "\" & f As dstDir & "\0" & f