Создание, копирование, перемещение и удаление папок

Создание папки с проверкой существования:

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists ("C:\fso") Then
WScript.Echo("folder exists and will be deleted")
objFSO.deleteFolder ("C:\fso")
WScript.Echo("clean folder created")
Set objFolder = objFSO.CreateFolder("c:\fso")
Else
WScript.Echo("folder does not exist and will be created")
Set objFolder = objFSO.CreateFolder("c:\fso")
End if

Создание множества папок:

Option Explicit
Dim numFolders
Dim folderPath
Dim folderPrefix
Dim objFSO
Dim objFolder
Dim i

numFolders = 10
folderPath = "C:\"
folderPrefix = "TempUser"

For i = 1 To numFolders
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder(folderPath & folderPreFix & i)
Next

WScript.Echo(i - 1 & " folders created")

Копирование папок:

Const OverWriteFiles = True 
WScript.Echo(" beginning copy " & Now)
sFolder = "c:\documents and settings"
dFolder = "\\s2\fileBu"

Set objFSO = CreateObject ("scripting.fileSystemObject")
objFSO.CopyFolder sFolder, dFolder , OverWriteFiles
WScript.Echo("ending copy " & Now)

Перемещение:

Set objFSO = CreateObject ("scripting.fileSystemObject")
objFSO.moveFolder "c:\fso","C:\fso1"

Удаление папок:

Option Explicit
Dim numFolders
Dim folderPath
Dim folderPrefix
Dim objFSO
Dim objFolder
Dim i

numFolders = 10
folderPath = "C:\"
folderPrefix = "TempUser"

For i = 1 To numFolders
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.deleteFolder(folderPath & folderPreFix & i)
Next

WScript.Echo(i - 1 & " folders deleted")
Интересное на сайте: 
0
Голосов пока нет

Оставить комментарий