En ASP, especialmente en los sistemas CMS que necesitan generar estados estáticos, a menudo se requiere que algunos archivos sean juzgados, creados y eliminados. Hoy, el editor de The Error New Technology Channel lo ha resuelto aquí, lo que básicamente satisface las necesidades básicas.
Funciones personalizadas comúnmente utilizadas en ASP para manejar la carga y eliminación de archivos
<%
'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '
'Todas las funciones VBS personalizadas
'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '
Función DeleteFile (FileName) 'Eliminar archivo
Si el nombre de archivo <> "" entonces
Establecer fso = server.createObject ("scripting.filesystemObject")
Si fso.fileExists (nombre de archivo) entonces entonces
FSO.DeleteFile Nombre de archivo
final si
Establecer FSO = nada
final si
función final
'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '
Función CreateIR (BYVAL LocalPath) 'El programa que crea un directorio. Si hay múltiples niveles de directorios, lo crea un nivel a la vez
En el currículum de error siguiente
LocalPath = reemplazar (localpath, "/", "/")
Establecer fileObject = server.createObject ("scripting.filesystemObject")
Patharr = Split (LocalPath, "/")
Path_level = Ubund (Patharr)
para i = 0 a path_level
if i = 0 entonces pathtmp = patharr (0) & "/" else pathtmp = pathtmp & patharr (i) & "/"
cpath = izquierda (pathtmp, len (pathtmp) -1)
Si no es fileObject.FoldeExists (CPATH), entonces FileObject.CreateFolder CPATH
próximo
Establecer fileObject = nada
Si err.number <> 0 entonces
Creationir = falso
Err.Clear
demás
Creationir = true
final si
función final
'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '
function saverandFileName (Byval szfilename) 'Genere un nuevo nombre de archivo aleatorio basado en el nombre del archivo original
aleatorizar
'rannum = int (90000*rnd) +10000
'if mes (ahora) <10 entonces c_month = "0" & mes (ahora) else c_month = mes (ahora)
'If Day (ahora) <10 entonces c_day = "0" & Day (ahora) else C_day = Day (ahora)
'If Hour (ahora) <10 entonces c_hour = "0" & Hour (ahora) else C_Hour = Hour (ahora)
'If mind (ahora) <10 entonces c_minute = "0" & minuto (ahora) else c_minute = minuto (ahora)
'If segundo (ahora) <10 entonces c_second = "0" y segundo (ahora) else C_Second = minuto (ahora)
fileExt_a = split (szFileName, ".")
fileExt = lcase (fileext_a (ubund (fileext_a)))
SaverAndFileName = reemplazar (reemplazar (ahora ":", ""), "-", ""), "", "") & int (10*rnd) & "." & FileExtExt
'GeneraterAndomFileName = Year (ahora) & C_Month & C_day & C_Hour & C_minute & C_SeCond & "_" & Rannum & "." & FileExt
función final
'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '
function jaron_replacer (strContent, start_string, end_string, reemplazar_string)
'Función de reemplazo de CMS: cadena de origen, primera parte, última parte, caracteres reemplazados
'Devuelve la cadena reemplazada
jaron_replacer = reemplazar (strContent, mid (strContent, instr (strContent, start_string), instr (strContent, end_string)+len (end_string) -1), reemplazar_string)
función final
'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '
function reemplazaPlus (strContent, start_string, end_string, reemplazar_string)
'En el documento, elimine todos los personajes entre el principio y el final
En el currículum de error siguiente
MarkCounts = Ubund (Split (StrContent, Start_string))
Prestring = strcontent
para i = 0 a MarkCounts
Startmark = instr (1, prestring, start_string, 1)
Si Startmark = 0 entonces salga por
Commark = Instr (1, Prestring, End_String, 1) + Len (End_String)
Verstring = Mid (Prestring, StartMark, Commark - StartMark)
Prestring = reemplazar (preestring, verstring, reemplazar_string)
próximo
reemplazo de reemplazo = Prestring
Si err.number <> 0 entonces Err.Clear
función final
'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '
%>
El artículo anterior trata sobre las funciones de procesamiento de archivos de uso común en ASP. Creo que todos conocen a la mayoría de ellos. El nuevo canal de tecnología incorrecto continuará recopilando un conocimiento más útil para usted. Espero que puedas entender las buenas intenciones del editor. Si te gusta este artículo, ¡continúa siguiéndonos!