FSO related

xiaoxiao2021-03-06  41

Use FSO to modify file-specific contents

Function FsoChange (Filename, Target, String)

Dim objfso, ObjcountFile, FileTempdata

Set objfso = server.createObject ("

Scripting.filesystemObject ")

Set objcountfile = objfso.opentextfile (server.mappath (filename), 1, true)

FileTempdata = ObjcountFile.Readall

ObjcountFile.Close

FileTempdata = Replace (FileTempdata, Target, String)

Set objcountfile = objfso.createtextfile (server.mappath (filename), true)

Objcountfile.write filetempdata

ObjcountFile.Close

Set objcountfile = Nothing

Set objfso = Nothing

END FUNCTION

Use the FSO to read the function of the file content

Function fsofileread (filename)

Dim objfso, ObjcountFile, FileTempdata

Set objfso = server.createObject ("

Scripting.filesystemObject ")

Set objcountfile = objfso.opentextfile (server.mappath (filename), 1, true)

FsofileRead = ObjcountFile.Readall

ObjcountFile.Close

Set objcountfile = Nothing

Set objfso = Nothing

END FUNCTION

Use the FSO to read the function of a row of files

Function FsolineDit (filename, linenum)

IF Linenum <1 THEN EXIT FUNCTION

DIM FSO, F, TEMPARRAY, TEMPCNT

SET FSO = Server.createObject ("

Scripting.filesystemObject ")

IF not fso.fileexists (server.mappath (filename)) THEN EXIT FUNCTION

Set f = fso.opentextfile (server.mappath (filename), 1)

IF not f.atendofstream Then

Tempcnt = f.readall

f.close

Set f = Nothing

Temparray = Split (Tempcnt, Chr (13) & chr (10))

If Linenum> Ubound (Temparray) 1 THEN

EXIT FUNCTION

Else

FSOLinedit = Temparray (LINENUM-1)

END IF

END IF

END FUNCTION

Use FSO to write a function of a row

Function FsolineWrite (FileName, Linenum, LineContent)

IF Linenum <1 THEN EXIT FUNCTION

DIM FSO, F, TEMPARRAY, TEMPCNT

SET FSO = Server.createObject ("

Scripting.filesystemObject ")

If not fso.fileexists (server.mappath (filename)) THEN EXIT FUNCTIONSET F = fso.opentextfile (server.mappath (filename), 1)

IF not f.atendofstream Then

Tempcnt = f.readall

f.close

Temparray = Split (Tempcnt, Chr (13) & chr (10))

If Linenum> Ubound (Temparray) 1 THEN

EXIT FUNCTION

Else

Temparray (LINENUM-1) = linecontent

END IF

Tempcnt = JOIN (Temparray, Chr (13) & chr (10))

Set f = fso.createtextfile (server.mappath (filename), true)

F.Write Tempcnt

END IF

f.close

Set f = Nothing

END FUNCTION

Use FSO to add files to new rows

Function FsoAppline (filename, linecontent)

DIM FSO, F

SET FSO = Server.createObject ("

Scripting.filesystemObject ")

IF not fso.fileexists (server.mappath (filename)) THEN EXIT FUNCTION

Set f = fso.opentextfile (server.mappath (filename), 8, 1)

F.Write Chr (13) & chr (10) & linecontent

f.close

Set f = Nothing

END FUNCTION

Read the final line of the file

Function fsolastline (filename)

DIM FSO, F, TEMPARRAY, TEMPCNT

SET FSO = Server.createObject ("

Scripting.filesystemObject ")

IF not fso.fileexists (server.mappath (filename)) THEN EXIT FUNCTION

Set f = fso.opentextfile (server.mappath (filename), 1)

IF not f.atendofstream Then

Tempcnt = f.readall

f.close

Set f = Nothing

Temparray = Split (Tempcnt, Chr (13) & chr (10))

Fsolastline = Temparray (Ubound (TempaRay))

END IF

END FUNCTION

Use FSO to get BMP, JPG, PNG, GIF file information (size, wide, high)

<%

'::: BMP, GIF, JPG and PNG :::

':: this function gets a specified number of bytes from any :::

'::: File, Starting At the Offset (Base 1) ::::

'::: :::

'::: passed: :::

'::: flnm => filespec of file to read :::

'::: offset => Offset at which to start reading :::' ::: bytes => How much bytes to read :::

'::: :::

': :::::::::::::::::::::::::: ::::::::::::::::::

Function getBytes (flnm, offset, bytes)

DIM OBJFSO

DIM Objftemp

DIM ObjTextStream

Dim lngsize

ON Error ResMe next

Set objfso = creteObject ("

Scripting.filesystemObject ")

'First, we get the filesis

Set objftemp = objfso.getfile (flnm)

LNGSIZE = Objftemp.size

Set objftemp = Nothing

FsoForReading = 1

Set objTextStream = objfso.opentextfile (flnm, fsoforreading)

IF offset> 0 THEN

Strbuff = ObjtextStream.read (Offset - 1)

END IF

iftes = -1 Then 'get all!

GetBytes = ObjtextStream.Read (LNGSIZE) 'Readall

Else

GetBytes = ObjTextStream.read (bytes)

END IF

ObjtextStream.close

Set objtextStream = Nothing

Set objfso = Nothing

END FUNCTION

': :::::::::::::::::::::::::: ::::::::::::::::::

'::: :::

'::: Functions to Convert Two bytes to a Numeric

Value (long) :::

'::: (Both Little-endian and big-endian) :::

'::: :::

': :::::::::::::::::::::::::: ::::::::::::::::::

Function LNGCONVERT (STRTEMP)

LNGCONVERT = CLNG (ASC (LEFT (STRTEMP, 1)) ((ASC (Right (strTemp, 1)) * 256))))))

END FUNCTION

Function LNGCONVERT2 (STRTEMP)

LNGCONVERT2 = ClNG (ASC (Right (strTemp, 1)) ((ASC (Left (Strtemp, 1)) * 256)))))))))

END FUNCTION

': :::::::::::::::::::::::::: ::::::::::::::::::

'::: :::

'::: this function does Most of the real work. It will attempt :::

'::: r r f, regardless of the extension, and will :::

'::: Identify if it is a graphical image. :::' ::: :::

'::: passed: :::

'::: flnm => filespec of file to read :::

'::: width => width of image :::

'::: height => Height of Image :::

'::: Depth => Color Depth (in Number of Colors) :::

'::: strimagetype => Type of Image (E.G. GIF, BMP, ETC.) :::

'::: :::

': :::::::::::::::::::::::::: ::::::::::::::::::

Function GFXSPEX (FLNM, Width, Height, Depth, StrimageType)

DIM STRPNG

DIM STRGIF

DIM STRBMP

DIM STRTYPE

Strtype = ""

StrimageType = "(unknown"

GFXSPEX = FALSE

Strpng = CHR (137) & chr (80) & chr (78)

Strgif = "gif"

StrBMP = CHR (66) & chr (77)

Strtype = getBytes (flnm, 0, 3)

IF strgif1 'is gif

StrimageType = "gif"

Width = LNGCONVERT (GetBytes (FLNM, 7, 2))

Height = LNGCONVERT (GetBytes (FLNM, 9, 2))

Depth = 2 ^ ((ASC (Gettes (FLNM, 11, 1)) and 7) 1)

GFXSPEX = TRUE

Elseif Left (Strtype, 2) = Strbmp Then 'Is BMP

StrimageType = "BMP"

Width = LNGCONVERT (GetBytes (FLNM, 19, 2))

Height = LNGCONVERT (GetBytes (FLNM, 23, 2))

Depth = 2 ^ (ASC (GetBytes (FLNM, 29, 1))))

GFXSPEX = TRUE

Elseif Strtype = STRPNG THEN 'IS PNG

StrimageType = "PNG"

Width = LNGCONVERT2 (GetBytes (FLNM, 19, 2))

Height = LNGCONVERT2 (GetBytes (FLNM, 23, 2))

Depth = GetBytes (flnm, 25, 2)

SELECT CASE ASC (Right (depth, 1))

Case 0

DEPTH = 2 ^ (ASC (Left (depth, 1))))

GFXSPEX = TRUE

Case 2

DEPTH = 2 ^ (ASC (Left (depth, 1)) * 3)

GFXSPEX = TRUE

Case 3

DEPTH = 2 ^ (ASC (Left (depth, 1))) '8

GFXSPEX = Truecase 4

DEPTH = 2 ^ (ASC (Left (depth, 1)) * 2)

GFXSPEX = TRUE

Case 6

DEPTH = 2 ^ (ASC (Left (depth, 1)) * 4)

GFXSPEX = TRUE

Case Else

DEPTH = -1

End SELECT

Else

Strbuff = Gettes (flnm, 0, -1) 'get alltes from file

LNGSIZE = LEN (STRBUFF)

FLGFOUND = 0

STRTARGET = CHR (255) & chr (216) & chr (255)

FLGFOUND = INSTR (Strbuff, Strtarget)

IF flground = 0 THEN

EXIT FUNCTION

END IF

StrimageType = "jpg"

LNGPOS = flgfound 2

Exitloop = false

Do while exitLoop = false and lngpos

Do While ASC (MID (Strbuff, LNGPOS, 1) = 255 and lngpos

LNGPOS = LNGPOS 1

loop

IF ASC (MID (Strbuff, LNGPOS, 1)) <192 or ASC (MID (Strbuff, LNGPOS, 1)> 195 THEN

LNGMARKERSIZE = LNGCONVERT2 (MID (Strbuff, LNGPOS 1, 2))

LNGPOS = LNGPOS LNGMARKERSIZE 1

Else

ExitLoop = true

END IF

loop

'

IF exitloop = false kil

Width = -1

HEIGHT = -1

DEPTH = -1

Else

HEIGHT = LNGCONVERT2 (MID (Strbuff, LNGPOS 4, 2))

Width = LNGCONVERT2 (MID (StrBuff, LNGPOS 6, 2))

Depth = 2 ^ (ASC (MID (Strbuff, LNGPOS 8, 1)) * 8)

GFXSPEX = TRUE

END IF

END IF

END FUNCTION

': :::::::::::::::::::::::::: ::::::::::::::::::

'::: Test Harness :::

': :::::::::::::::::::::::::: ::::::::::::::::::

'To test, we'll Just Try to show all files with a .gif extension in the root of c:

Set objfso = creteObject ("

Scripting.filesystemObject ")

Set objf = objfso.getfolder ("c: /")

Set objfc = Objf.files

Response.write "

"for Each F1 in Objfc

IF INSTR (ucase (f1.name), ".gif") THEN

Response.write "

" & f1.name & " " & f1.datecreated & " " & f1.size & " < TD> "

IF GFXSPEX (f1.path, w, h, c, startpe) = true kil

Response.write W & "X" & H & "& C &" Colors "

Else

Response.write ""

END IF

Response.write " "

END IF

NEXT

Response.write ""

Set objfc = Nothing

Set objf = Nothing

Set objfso = Nothing

%>

转载请注明原文地址:https://www.9cbs.com/read-66330.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.039, SQL: 9