Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking File/Folder Permissions

Status
Not open for further replies.

pickletech

IS-IT--Management
Dec 20, 2004
88
US
Hello everyone. I am running a script that searches a hard drive for certain files. Unfortunately I keep getting a 'Permission Denied' error. I am not sure why I am getting it because I am not changing the files. Is there any way to check permissions on a file/folder? Below is my code...

Dim FSO, WSH, objDirectory, objFile, TheFiles

Set FSO = CreateObject("Scripting.FileSystemObject")
Set WSH = CreateObject("Wscript.Shell")


Set objDirectory = FSO.GetFolder(InputBox("Enter Beginning Folder Path"))
Set TheFiles = objDirectory.Files

Parentfolder = mid(fso.GetFolder(objDirectory),InStrRev(fso.GetFolder(objDirectory),"\",-1,0)+1,len(fso.GetFolder(objDirectory)) - InstrRev(fso.GetFolder(objDirectory),"\",-1,0))
strSearchString = InputBox("Enter search string")


If FSO.FileExists ("FileNames " & Parentfolder & ".txt") Then
FSO.DeleteFile "FileNames " & Parentfolder & ".txt"
End If

Set txtFileName = FSO.CreateTextFile ("FileNames " & Parentfolder & ".txt",TRUE)
Set txtFileName = Nothing
Set txtFileName = FSo_OpenTextFile("FileNames " & Parentfolder & ".txt", 8)

WorkWithSubFolders objDirectory

txtFileName.Close


'****************************************************************************************
Sub WorkWithSubFolders(objDirectory)
Dim MoreFolders, TempFolder

ListFilesWithString objDirectory
Set MoreFolders = objDirectory.SubFolders

For Each TempFolder In MoreFolders
WorkWithSubFolders TempFolder
Next

End Sub

'****************************************************************************************
Sub ListFilesWithString(objDirectory)
Dim TheFiles

Set TheFiles = objDirectory.Files
For Each objFile In TheFiles
strFileName = fso.GetFileName(objFile.Path)
If InStr(1, strFileName, strSearchString, 1) > 0 Then
txtFileName.writeline objFile.Path & vbtab & objFile.Size
end If
Next
End Sub

The error happens with the ListFilesWithString Sub.
Thank You,
Pickletech
 
It looks to me like you delete a file if it exists then create and open a file.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
oh no, that is just the text file it creates when the script is running, to tell you which files it found.

-Pickletech
 
Have you the rights to browse all the directory tree ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
i do NOT have read access to all files/folders. The problem is I have list access, so it can get the list of files (TheFiles) but when it tries to read each file (objFile) I am getting the error. I reposted the problem area for clarity...

For Each objFile In TheFiles
strFileName = fso.GetFileName(objFile.Path)
If InStr(1, strFileName, strSearchString, 1) > 0 Then
txtFileName.writeline objFile.Path & vbtab & objFile.Size
end If
Next

I have no clue how to get around this.
 
i tried using putting 'on error resume next' at the beginning of the problem area, and a 'on error goto 0' at the end of it. This did not help, because then it would just go to the next folder, without searching the rest of the files.

thanks everyone
 
Have you tried this ?
strFileName = objFile.Name

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Actually I just rewrote that part. This is what it looks like now.

FileName = Right(objFile,Len(objFile) - InStrRev(objFile, "\", -1))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top