【问题标题】:Need to move a variable folder based on date需要根据日期移动变量文件夹
【发布时间】:2016-04-30 16:00:56
【问题描述】:

这就是我所拥有的。

stSourceFolder = "C:\Users\HIRENS\Admin\" & Replace(CStr(Date()), "/", ".")
stTargetFolder = "C:\Users\HIRENS\Admin\HIRENS\Admin\backup\" & _
                 Replace(CStr(), "DDMMYY")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set fso = CreateObject("Scripting.FileSystemObject")
' The script will error out if it tries to create a directory that already exist
' so it is better to check for it first and only attempt to create it if it does
' not exist.
If Not fso.FolderExists(strDirectory) Then
   ' If it gets here then the folder for the current date does not yet exist and
   ' therefore is created.
   Set objFolder = fso.CreateFolder(stTargetFolder)
End If
' This copies the files and overwrites them if they exist.
fso.CopyFolder stSourceFolder, destinationDir, OverwriteExisting
' If you entend to automate this script you should remove or rem out this next
' line.
WScript.Echo "Done"
'If the target-folder does not exist then it will be created.
objFSO.CopyFolder stSourceFolder, stTargetFolder

MsgBox "Folder copied"

Set fsoObj = Nothing

【问题讨论】:

  • 那是一些很棒的代码。你只是炫耀还是有问题?
  • 这是一个问题……问题在标题中……抱歉造成误解。我需要移动的文件夹名称是昨天的日期 DDMMYY 到另一个文件夹。

标签: vbscript directory


【解决方案1】:
`On Error Resume Next

Dim sb : Set sb = CreateObject("System.Text.StringBuilder")
sb.AppendFormat "{0:ddMMyy}", Now() -1

  '-----------------------------------------------------
 TargetFolder = "C:\Users\"& sb.ToString &""
 Set x = CreateObject("Scripting.FileSystemObject")
 x.MoveFolder ""& TargetFolder &"" , "C:\Users\backup\"

'^^^ To move Variable folder DDMMYY
'------------------------------------------------------------

 Dim fso, count, src, folder, file 
 Set fso = CreateObject("Scripting.FileSystemObject") 
 src = "C:\Users\backup\"& sb.ToString &"\"
 stringtofind = "txt"
 Set folder = fso.GetFolder(src) 
 count = 0 
 For Each file In folder.files 
 If instr(LCase(file.name), LCase(stringtofind)) > 0 Then
 count = count + 1 
  End If 
 Next 

    WScript.Echo "PXE Files Count: " & count`

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多