Войти

Показать полную графическую версию : [решено] скрипт, который создаст текстовый файл и запишет в него инфу о всех папках


daniil_im
19-09-2017, 17:18
Заданием заключается таким образом: нужен скрипт, который создаст текстовый файл в папке документов моего профиля например,(хотя можно просто на каком нибудь диске) и запишет в него инфу о всех папках в папке диска C:\ моего ПК об их атрибутах
У меня получился примерно такой код но он естественно не работает... Подскажите, я хоты бы был в правильном направлении?:D Подскажите начинающему, как должен выглядеть правильный код этого задания:(
Dim fso, ts
Const ForWriting = 2
Set fso = CreateObject("Scripting. FileSystemObject")
Set ts = fso.OpenTextFile("c:\test.txt", ForWriting, True)

Iska
19-09-2017, 19:08
Подскажите начинающему, как должен выглядеть правильный код этого задания »
Примерно так:
Option Explicit

Dim strDestFile

Dim objTS
Dim objFolder


With WScript.CreateObject("Scripting.FileSystemObject")
strDestFile = .BuildPath(WScript.CreateObject("WScript.Shell").SpecialFolders.Item("MyDocuments"), "текстовый файл.txt")

If .DriveExists("C:") Then
Set objTS = .CreateTextFile(strDestFile, True, True)

For Each objFolder In .GetFolder("C:\").SubFolders
objTS.WriteLine ComposeAttributesString(objFolder.Attributes) & vbTab & objFolder.Name
Next

objTS.Close
Set objTS = Nothing
Else
WScript.Echo "Drive C: not exists."
WScript.Quit 1
End If
End With

WScript.Quit 0

Function ComposeAttributesString(intAttributes)
Dim strResult

strResult = ""

If intAttributes And 16 Then strResult = strResult & "D" Else strResult = strResult & " "
If intAttributes And 2048 Then strResult = strResult & "C" Else strResult = strResult & " "
If intAttributes And 1024 Then strResult = strResult & "L" Else strResult = strResult & " "
If intAttributes And 32 Then strResult = strResult & "A" Else strResult = strResult & " "
If intAttributes And 4 Then strResult = strResult & "S" Else strResult = strResult & " "
If intAttributes And 2 Then strResult = strResult & "H" Else strResult = strResult & " "
If intAttributes And 1 Then strResult = strResult & "R" Else strResult = strResult & " "

ComposeAttributesString = strResult
End Function




© OSzone.net 2001-2012