-
Notifications
You must be signed in to change notification settings - Fork 0
/
newkey.bat
74 lines (61 loc) · 2.2 KB
/
newkey.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@echo off
SETLOCAL
set downloaddir=%userprofile%\Downloads
set destdir=%userprofile%\Putty
set filename=key.ppk
goto main
:test
echo %downloaddir%
echo %destdir%
echo %filename%
echo %downloaddir%\%filename%
goto end
:: after download new ppk file, copy to specified location overwriting existing
:: or provide a reminder to download by deleting after copy or move the file
:: no file in source dir == did not download today/when needed
:main
if exist %downloaddir%\%filename% (
forfiles /p "%downloaddir%" /s /m %filename% /D 0 /C "cmd /c dir @file"
forfiles /p "%downloaddir%" /s /m %filename% /D 0 /C "cmd /c move /Y %filename% %destdir%\%filename%"
if exist %downloaddir%\%filename% (
echo %filename% is older than today and was not moved
echo but will now be deleted
forfiles /p "%downloaddir%" /s /m %filename% /D -1 /C "cmd /c echo @file"
forfiles /p "%downloaddir%" /s /m %filename% /D -1 /C "cmd /c del /q @file"
) else (
echo %filename% has been moved to %destdir% !
)
goto cleanup
) else (
echo Please download a new %filename%
goto cleanup
)
:cleanup
:: For any other type of key files, or older ppk that didn't get moved
:: older than (last modified longer ago than, due to windows limitations)
:: seek and destroy
if exist %downloaddir%\*.rdp (
echo Cleaning up old rdp files in %downloaddir%
forfiles /p "%downloaddir%" /s /m *.rdp /D -1 /C "cmd /c echo @file"
forfiles /p "%downloaddir%" /s /m *.rdp /D -1 /C "cmd /c del /q @file"
)
if exist %downloaddir%\*.openssh (
echo Cleaning up old openssh files in %downloaddir%
forfiles /p "%downloaddir%" /s /m *.openssh /D -1 /C "cmd /c echo @file"
forfiles /p "%downloaddir%" /s /m *.openssh /D -1 /C "cmd /c del /q @file"
)
if exist %downloaddir%\*.pem (
echo Cleaning up old pem files in %downloaddir%
forfiles /p "%downloaddir%" /s /m *.pem /D -1 /C "cmd /c echo @file"
forfiles /p "%downloaddir%" /s /m *.pem /D -1 /C "cmd /c del /q @file"
)
if exist %downloaddir%\*.ppk (
echo Cleaning up old ppk files in %downloaddir%
forfiles /p "%downloaddir%" /s /m *.ppk /D -1 /C "cmd /c echo @file"
forfiles /p "%downloaddir%" /s /m *.ppk /D -1 /C "cmd /c del /q @file"
)
goto end
:end
pause
ENDLOCAL
Exit