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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

prevent permission denied

Status
Not open for further replies.

Dalie

Programmer
Feb 16, 2009
17
NL
I use the following script to lowercase names from folders. The script works fine. It produces an error (Permission Denied) however if I have a file opened which stands in a to be renamed directory. Is there a way to prevent this error from occurring? Any help, suggestions (even for the script I use) is welcome!
Code:
Dim fso
Dim fol

Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set fol = fso.GetFolder(".")

For each oSubFolder In fol.SubFolders
    If oSubFolder.Name <> UCase(oSubFolder.Name) Then
	oSubfolder.Move UCase(oSubfolder.Name)
End If
Next
 
You can add the following line before the line generating the error.

On Error Resume Next

It will ignore the errors and continue attempting to process the rest of the script. It will of course not be able to do anything with the file you have opened.
 
Thanks, that indeed prevents the error from occurring. But also leaves the folder unchanged. Is it even possible to change the name in the situation I described? Because lowercasing files doesn't give the error (when opened...)
 
I believe when you have a file open the operating system will prevent any change to any folder name its path. I could be wrong...
 
You're right, you can't rename a folder when the "path" is in use. One other question though; I'd like to make the script a little more flexible by declaring a variable which determinse the case. To clarify:

Code:
Dim theCase
[b]theCase[/b] = UCase

...
If oSubFolder.Name <> [b]theCase[/b](oSubFolder.Name) Then
...

Any suggestions? Thanks,
Dalie
 
You'd really have to write your own function for that task (as UCase is itself a Function). Something like (untested from the top of my head)
Code:
Function ChangeCase(input, case)

If case = 0 then
ChangeCase = LCase(input)
ElseIf case = 1 then
ChangeCase = UCase(input)
End If

End Function
That would have 0 for lowercase and 1 for uppercase.

Call it like:
Code:
Dim theCase
theCase = 1 'for uppercase, 0 for lowercase

...
If oSubFolder.Name <> ChangeCase(oSubFolder.Name, thecase) Then
I think that will work (not done a lot of functions in VBScript! [wink])

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top