2015-06-30 22 views
1

我需要一個計算機列表(IP或PC名稱),它們都是在CSV格式的同一個域中。掃描每臺計算機的特定文件夾名稱。該文件夾將是arcXXXof。這些x是每個PC的散列和變化。如果找到該文件夾​​,則需要將文件夾路徑輸出到CSV並在掃描每臺計算機時附加。我的編程是有限的,我只知道Java。由於這將從服務器運行,因此需要本地管理權限才能在本地機器上運行。我的經理建議我使用VBS,但我以前從來沒有寫過。掃描計算機的文件和輸出文件夾的位置

我目前的障礙是一個錯誤「預計然後」這是我的循環。

子遞歸(strFolderPath) 昏暗objFolder 設置objFolder = objFSO.GetFolder(strFolderPath)「讀取文件夾從遞歸拉

Dim objSubFolder 

dim folderStart 'grabs the first 2 characters of the file name. Should match 'of' if correct folder 
Dim folderEnd 'grabs the last 6 (test) characters of the folder name, should match arc.txt if correct 

Global checkEnd 
set checkEnd = "arc" 'checks for "arc" at ending 

Global checkStart 
set checkStart = "of" 'used to check if folder name is correct path 



For Each objSubFolder in objFolder 'for every Folder scanned 
'Scans the name of the Folder, objSubFolder, for an ending of 「arc", and beginning of 「of」 (testing) 
set folderName = objSubFolder.name 
Set folderEnd = right(folderName, 3) 
set folderStart = left(folderName, 2) 
dim folderName 

    if folderName = testFolderName 
    then WScript.Echo objSubFolder 
    'If folderEnd = checkEnd and 
    'If folderStart = checkStart 

    'Add Folder location to array, set array to next object 
    'Then fLocations(i) = object.GetAbsolutePathName(objSubFolder) and i = i+1 
else 
    End If 
Next 
'recursive for searching new folder 
For Each objSubFolder in objFolder.Subfolders 
    Call Recurse(objSubFolder.Path) 
Next 
+0

對於解釋不好,我表示歉意。腳本需要搜索文件並輸出它的文件夾路徑,而不是文件本身。 – mwhittaker1

+0

可能會更好地讓每臺PC的能力爲您工作,並部署一個登錄腳本,用於在用戶登錄時搜索用戶的PC,然後寫入共享網絡文本文件。需要搜索多少臺PC? – Bond

+0

這可能很方便!但是,我仍然不知道該怎麼做:)大約需要搜索120臺電腦。 – mwhittaker1

回答

0

OK,你可以使用正則表達式匹配的名字。它定義了前面,在全球範圍內:

Dim re 
Set re = New RegExp 
re.IgnoreCase = True 
re.Pattern = "^arc\w{3}of$" 

我使用\w,這相當於[a-zA-Z_0-9]。如果您只需要數字(\d)或其他三種字符,則可以更改此設置。

然後,在你Recurse功能,測試文件夾名反對:

For Each objSubFolder in objFolder.SubFolders 

    ' See if this folder name matches our regex... 
    If re.Test(objSubFolder.Name) Then 

     ' Match. Just display for now... 
     WScript.Echo objSubFolder.Path 

    End If 

    ' Test its subfolders... 
    Recurse objSubFolder.Path 

Next 

提示:當你正在開發從你的代碼中刪除On Error Resume Next或者你可能會錯過所有類型的bug,並引發各種的頭痛。

相關問題