VBS can't find directory - 'Path Not Found'

Zero picture Zero · Jun 13, 2012 · Viewed 17.2k times · Source

I have a script that obtains information about the current folders and subfolders within a specific directory. It works great, but I have stumbled across a strange issue:

dim FSO, objFolder, datafolder, foldername, objSubfolder, totalSize
dim objSubfolder2, objFolder2, mSize, size, today, dateLastMod

foldername = "D:\folder\subfolder"
set FSO = CreateObject("Scripting.FileSystemObject")
set objFolder = FSO.GetFolder(foldername) 
set colSubfolders = objFolder.Subfolders
today = Now
ShowFolderDetails objFolder

Function ShowFolderDetails(oF)

    datafolder = oF.Size/1073741824
    wscript.echo oF.Name & " :Size= " & datafolder & " GB"
    wscript.echo oF.Name & " #Files= " & oF.Files.Count
    wscript.echo oF.Name & " #Folders= " & oF.Subfolders.count
    wscript.echo oF.Name & " Date Last Modified= " & oF.DateLastModified
    totalSize = totalSize + datafolder

end Function

And there is more to follow, but my issue is I get a path not found when I call that function.

The folder is not located on the C:\ drive - which shouldn't be an issue. I have done this same script but changed foldername = D:\folder\differentsubfolder which works perfectly. But when I change it back to the other folder, it gives me a path not found error.

I also tried putting everything below set FSO = CreatObject("Scripting.FileSytemObject") within an IF statement:

IF FSO.FolderExists(foldername) Then ....

This does enter in that IF statement, which makes me believe the VBS sees it, but I still get that error at line 17 (datafolder = oF.Size/1073741824).

I have tried putting in the full folder path where the variable foldername is located (surrounded in quotes).

I tried running my vbs pointed to other directories and it runs 100%. Its just that specific folder. There are no spaces in the folder name. Is there anything else I am missing? I have full admin access to the D:\

Answer

peter picture peter · Jun 14, 2012

I bet it isn't a hidden file or folder that is the cause but a system file like eg Thumbs.db thas sits in many folders containing images, too see them edit your folder options to see systemfiles, remove the systemfile and try again. When you ask the size of a folder you need access to ALL folders and files beneath it. If you try your script on eg your profilefolder you certainly will get errors, administrator or owner of that folder or not.

In case it could help, here a script that gives the attributes from a file

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("c:\ruby193.zip")
If objFile.Attributes AND 0 Then
    Wscript.Echo "No attributes set."
End If    
If objFile.Attributes AND 1 Then
    Wscript.Echo "Read-only."
End If    
If objFile.Attributes AND 2 Then
    Wscript.Echo "Hidden file."
End If    
If objFile.Attributes AND 4 Then
    Wscript.Echo "System file."
End If    
If objFile.Attributes AND 32 Then
    Wscript.Echo "Archive bit set."
End If    
If objFile.Attributes AND 64 Then
    Wscript.Echo "Link or shortcut."
End If    
If objFile.Attributes AND 2048 Then
    Wscript.Echo "Compressed file."
End If