-
July 11th, 2004, 08:24 AM
#1
CreateTextFile Permission Denied??
I am using CreateTextFile and if the file doesn't already exist, it creates it OK. If it does exist I can delete it using FSO.DeleteFile and it gets deleted but then the CreateTextFile fails with permission denied. What's really bugging me is I had this working for a while and now I can't get around it.
Any clues?
-
July 11th, 2004, 08:32 PM
#2
Make it wait for a bit before you do the createfile - its probably still deleting. Also, you might want to consider using "Kill" rather than 'deleteFile'
Be nice to Harley riders...
-
July 12th, 2004, 06:55 AM
#3
I changed to Kill and I added this timer (from MSDN) before attempting the CreateTextFile :
Dim PauseTime, Start, Finish, TotalTime
If (MsgBox("Press Yes to pause for 5 seconds", 4)) = vbYes Then
PauseTime = 5 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
Finish = Timer ' Set end time.
TotalTime = Finish - Start ' Calculate total time.
MsgBox "Paused for " & TotalTime & " seconds"
Else
End
End If
I tried it at 5 seconds and then at 10 seconds. I still get permission denied if the file existed.
I have a filList that has that file in it. I thought maybe that was causing the problem but I even stripped that code & the box out and I still fail. I'm stumped.
-
July 12th, 2004, 07:36 AM
#4
As it seems a bit odds, I tested with this code on Windows 2000
server, and had no matter at all - I am logged in as
administrator... - I put a breakpoint on the delete, and execute a
step at a time going to see if file was correctly deleted and
recreated. Then I try without any breakpoint and it went on fine.
This seems to indicate your is not a scripting problem per se...:
Code:
Option Explicit
Private Sub Command1_Click()
Dim Fso As Scripting.FileSystemObject
Dim Counter As Integer
Set Fso = New Scripting.FileSystemObject
For Counter = 0 To 2
If Fso.FileExists("c:\test.txt") Then
Fso.DeleteFile "c:\test.txt", True
End If
Dim tStream As TextStream
Set tStream = Fso.CreateTextFile("c:\test.txt", True)
tStream.Write "Hello World"
tStream.Close
Next
End Sub
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
July 12th, 2004, 07:50 AM
#5
I'm thinking it has more to do with the file extension I am working with. I should have explained better that I reading an existing .txt file and creating a .smi file (MediaPlayer captioning file). If the .smi doesn't pre exist FSO CreateTextFile creates it OK. If it did exist even though I deleted it, the create fails. I even tried to create it as a TEMP.txt then do a FSO COPYFILE thinking that the CreateTextFile had a problem with the .smi extension but the copyfile also fails with permision denied. I even tried deleteing the original .txt file before doing the create. Same results.
This is stange but there's got to be a way around it.
Is there a file rename capability?
-
July 12th, 2004, 09:57 AM
#6
Know nothing about .smmi files, but - unless they are immediately opened, they should not make Fso behave differently - is mediaplayer opened while you're doing this operation?
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
July 12th, 2004, 11:05 AM
#7
.smi files are just txt files with a special format to control the captions that are displayed below the video in MediaPlayer. You can code them up as .txt in notepad and then rename them to .smi which is essentially what the utility I am writing is trying to accomplish.
Good thought about MediaPlayer maybe holding onto it. That may be the culprit. This timing is bizarre though. I changed it to do the delete of the .smi before ever starting Mediaplayer and I put a msgbox in after the delete. I went to the directoy at that point and the file is still in there. It wouldn't let me rename it at that point. So the delete isn't actually taking place when I execute the FSO delete.
I need to play around some more.
-
July 12th, 2004, 11:10 AM
#8
Found it!
I had to move the delete up prior to having set MediaPlayer.FileName = ....mp3 file that is going to be played. Even though I hadn't started the player yet it had hold of the associated .smi file if it existed.
Thanks for the tips.
-
October 31st, 2008, 12:47 PM
#9
Re: CreateTextFile Permission Denied??
Hi all,
I am using this simple code
<%
dim fs,tfile
set fs=Server.CreateObject("Scripting.FileSystemObject")
set tfile=fs.CreateTextFile("somefile.txt",true)
tfile.WriteLine("Hello World!")
%>
it gives me a permission denied at this line
fs.CreateTextFile("somefile.txt",true)
can any one help me out please.
been stuck with this for quite some time.
thank you
-
October 31st, 2008, 01:28 PM
#10
Re: CreateTextFile Permission Denied??
another thing...
i have all the permissions on the server
and the exact message is as follows
Microsoft VBScript runtime error '800a0046'
Permission denied
/enlacefl/blogforms.asp, line 36
thanks again
-
October 31st, 2008, 02:13 PM
#11
Re: CreateTextFile Permission Denied??
5ms is way too slow, even for windows. It needs 15-20ms to process anything. Change it to 500, or 1000, and try it again.
Also, you are declaring this as OBJECTS which isn't optimal.
Code:
Option Explicit
'
' Add a reference to Microsoft Scripting Runtime
Sub GetFileInfo(strPath As String)
' On Error Resume Next
Dim s1 As String
Dim f As Object, fso As New FileSystemObject
Set f = fso.GetFolder(strPath)
s1 = f
MsgBox s1 & vbCrLf & _
"Date Created " & f.DateCreated & vbCrLf & _
"Last Modified " & f.DateLastModified & vbCrLf & _
"Last Accessed " & f.DateLastAccessed
End Sub
Private Sub Form_Activate()
GetFileInfo "c:\windows\"
End Sub
Last edited by dglienna; October 31st, 2008 at 03:35 PM.
-
October 31st, 2008, 02:42 PM
#12
Re: CreateTextFile Permission Denied??
Just simply try,
dim fso as filesystemobject
private sub load ()
if fso.fileexist(directoryofchoice) = false then
open (directoryofchoice)for output as #1
close #1
end if
open (directoryofchoice)for output as #1
doevents
close #1
end sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|