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

fso code question /approach

Status
Not open for further replies.

LikeThisName

Vendor
May 16, 2002
288
US
Project: Need to allow people to access files from intranet but only edit them from PCDOCS where changes are recorded.

Solution: CopyFile on the fly and have them open that, or preferably open file or copy in read-only format

Approach: Feel Free to question this)
Since I can't write to a temp folder on clients pc due to virus scanner, nor can can i overwrite temp file in intranet directory due to permissions, i wanted to increment the destFile and then I'll go from there. whether that's manually deleting the extra files every month or whatever

CODE: (INCREMENT DOESN'T SEEM TO WORK
Code:
<%
dim fso, sourceFile, destFile, i
Set fso = Server.CreateObject("Scripting.FileSystemObject")
sourceFile = "\\c_web\intranet\Modules\PSW\TESTING.doc"
destPath = "\\c_web\intranet\Modules\PSW\"
destFile = "MyTempFile.doc"
destFilePath = destPath & destFile

if fso.FileExists(destFile) then
  destFile = destFile & "0"
  i = 1
  do while not fso.FileExists(destFilePath)
    destFile= left(destFile,(len(destFile)-1)) & i
    destFilePath = destPath & destFile
    i=i+1
  loop
end if

fso.CopyFile sourceFile,destFilePath,true
Set fso = Nothing
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>

<P><a href="./<%=destFile%>">open file</a></P>

</BODY>
</HTML>

LikeThisName <- ? Sorry It's Taken =)
 
caught this:
if fso.FileExists(destFile) then
should be
if fso.FileExists(destFilePath) then

something else is still wrong?

LikeThisName <- ? Sorry It's Taken =)
 
another problem i found was I was incrementing after .doc not before. so i fixed that. still could not get my while loop to work so i just used a for loop. i probably ought to talk to network and just change permissions to particular folder. still open to suggestions. i always want to learn the better way.
Code:
dim fso, sourceFile, destFile, i
Set fso = Server.CreateObject("Scripting.FileSystemObject")
sourceFile = "\\c_web\intranet\Modules\PSW\TESTING.doc"
destPath = "\\c_web\intranet\Modules\PSW\"
destFile = "MyTempFile.doc"
destFilePath = destPath & destFile
for i =0 to 100
  if fso.FileExists(destFilePath) then
    destFile = left(destFile, len(destFile)-4)
	destFile= left(destFile,(len(destFile)-1)) & i & ".doc"
	destFilePath = destPath & destFile
  end if
next
fso.CopyFile sourceFile,destFilePath,true
Set fso = Nothing

LikeThisName <- ? Sorry It's Taken =)
 
folder was read-only which is why i couldn't delete the file. i was able to change that, and now no loops are necessary
Code:
if fso.FileExists(destFilePath) then
  fso.DeleteFile destFilePath
end if
fso.CopyFile sourceFile,destFilePath,true

LikeThisName <- ? Sorry It's Taken =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top