Created
August 14, 2014 17:08
-
-
Save fabioadrianosoares/e48207b390b578a62450 to your computer and use it in GitHub Desktop.
Mover arquivos para sub pastas (ano/mes/dia) de acordo com a ultima modificacao
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
option explicit | |
dim fs | |
Set fs = CreateObject("Scripting.FileSystemObject") | |
main | |
sub main () | |
dim f, r, dias, extensao | |
if wscript.arguments.count <> 2 then | |
wscript.echo "informe a extensao e a quantidade de dias a mover" | |
wscript.quit(1) | |
else | |
on error resume next | |
extensao = wscript.arguments(0) | |
dias = int(wscript.arguments(1)) | |
if err.number <> 0 then | |
wscript.echo "informe a extensao e a quantidade de dias a mover: " | |
wscript.echo " cscript /nolog txt 365 " | |
wscript.quit(2) | |
end if | |
on error goto 0 | |
end if | |
Set f = fs.GetFolder(".") | |
wscript.echo "Mover arquivos em: " + f.path + "? (sim/nao)" | |
r = wscript.stdin.readline() | |
if (trim(lcase(r)) = "sim") then | |
processar f, dias, extensao | |
else | |
wscript.echo "Não fazer nada." | |
end if | |
end sub | |
sub processar(byref pasta, byval dias, byval extensao) | |
dim arquivo | |
wscript.echo "procurando os arquivo """ & extensao & """" | |
For Each arquivo in pasta.Files | |
if lcase(right(arquivo.name, len(extensao)+1)) = lcase("." & extensao) then | |
if DateDiff("d", arquivo.DateLastModified, now) > dias then | |
mover arquivo | |
end if | |
end if | |
Next | |
end sub | |
sub mover(byref arquivo) | |
Dim destino | |
destino = ".\" & year(arquivo.DateLastModified) | |
criar destino | |
destino = destino & "\" & month(arquivo.DateLastModified) | |
criar destino | |
destino = destino & "\" & day(arquivo.DateLastModified) | |
criar destino | |
wscript.echo "mover " & arquivo.name & " - criado " & DateDiff("d", arquivo.DateLastModified, now) & " - " & arquivo.DateLastModified & " dias" | |
arquivo.move destino & "\" | |
end sub | |
sub criar(byref caminho) | |
if not fs.FolderExists(caminho) then | |
fs.CreateFolder caminho | |
wscript.echo "criar " & caminho | |
end if | |
end sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment