Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ECHO OFF
- mode 1000
- SETLOCAL enableDelayedExpansion
- Color 06
- Set "LogFilesDir=%~dp0"
- IF NOT EXIST "!LogFilesDir!logs" MD "!LogFilesDir!logs"
- Set "LogFilesDir=!LogFilesDir!logs\"
- :main
- IF exist "!LogFilesDir!*.log" (
- CHOICE /C ny /M "Remove previous Logs?"
- IF !errorlevel!==2 (
- DEL /Q !LogFilesDir!*.log 2>nul
- ECHO Logs Removed.
- TIMEOUT 1 >nul
- )
- )
- :selectDir
- cls
- Color 03
- CHOICE /N /C 12345 /M "[Select Directory To Log] 1: Root. 2: User Profile. 3: System. 4: App_Data 5: Other"
- IF !errorlevel!==5 GOTO :Drop
- IF !errorlevel!==4 GOTO :App_Data
- IF !errorlevel!==3 GOTO :System
- IF !errorlevel!==2 GOTO :User
- IF !errorlevel!==1 GOTO :Root
- GOTO :selectDir
- :System
- (Set "LogDir=!WinDir!")
- GOTO :Confirm
- :User
- (Set "LogDir=!userprofile!")
- GOTO :Confirm
- :Root
- (Set "LogDir=%~d0\")
- GOTO :Confirm
- :App_Data
- (Set "LogDir=!LOCALAPPDATA!")
- GOTO :Confirm
- :Drop
- (Set /p "LogDir=[Enter or Drop Directory to Log:]<")
- GOTO :Confirm
- :Confirm
- IF Not Exist "!LogDir!" (
- cls
- Color 04
- ECHO Invalid Directory Entered.
- Timeout 1 > nul
- GOTO :selectDir
- )
- REM CHOICE /C ny /M "Confirm: !LogDir!"
- REM IF NOT !errorlevel!==2 GOTO :selectDir
- :: REM - The Directory being searched & logged
- CD !LogDir!
- :: REM - Variable used to display total number of files logged.
- Set totalFiles=0
- cls
- CHOICE /N /C pa /M "[Log (A)ll Extensions OR (P)redefined Extensions:]"
- IF ERRORLEVEL==2 GOTO :log_all
- :log_predefined
- cls
- :: REM - For loop calls a function that logs files according to extension type.
- FOR %%a in (vbs,exe,ps1,bat,txt,sav,docx,pdf,ini,wav,mp3,mp4,ico,png,jpg,gif,bmg,png) DO (
- Set "ext=%%a"
- CALL :Get_DateTime
- CALL :process
- )
- FOR /L %%a IN (5,1,40) DO (
- ECHO [%%a;1H[K
- )
- ECHO [6;1H[32mInventory Complete
- pause >nul
- exit
- :process
- :: REM - assign path for log
- Set "Storefile=!LogFilesDir!!ext!FILES!T_D!.log"
- :: REM - Variable used for displaying filecount for current ext being logged
- Set Found=0
- :: REM - Variable used to in array to display groups of files logged
- Set Dcount=0
- :: REM - Increments counts used for display of chosen Information, Displays Status, Appends files found to log.
- For /R %%b IN (*.%ext%) DO (
- Set /a Dcount+=1
- Set /a totalFiles+=1
- Set /a Found+=1
- Set name=%%~nb
- Set location=%%~dpb
- ECHO [37m[1;1H[K !Found! !EXT! [33mfiles located [37m!totalFiles! [36mfiles logged in Total.
- ECHO [31m[2;1H[K Searching !location!...
- Set Line[!Dcount!]=%%b
- ECHO [32m[3;1H[K !name! [32m
- ECHO [4;1H[K [33mOn !T_D![34m
- ECHO(%%~b>>"%Storefile%"
- IF !Dcount!==35 (CALL :Display)
- )
- GOTO :eof
- :: REM - Function to display array of logged files in groups of 35.
- :Display
- Set Dcount=0
- For /L %%a IN (1,1,35) DO (
- Set /a Offset=%%a
- Set /a Offset=!Offset!+5
- ECHO [!Offset!;1H[K[34m !Line[%%a]!
- )
- GOTO :EOF
- :log_all
- CALL :Get_DateTime
- cls
- :: REM - For loop calls a function that logs files according to extension type.
- Set "N_E_F=0"
- FOR /R %%a in (*.*) DO (
- Set "PathOfFile=%%a"
- Set "ext=%%~xa"
- IF EXIST "!PathOfFile!" (
- IF DEFINED ext (CALL :process_all "!PathOfFile!")
- Set ext=
- ) else (
- Set /a "N_E_F+=1"
- ECHO [33m[1;1H[K [[31m!N_E_F![33m] Files with no Extension Encountered.
- ECHO([2;1H[K[90m"%%~pa"
- ECHO([3;1H[K[90m"%%~dpnxa"
- REM delay progress to allow reading of extensionless file info
- For /L %%b IN (1,1,1000) DO (
- Set Delay=Delayed%%b
- )
- )
- )
- ECHO [6;1H[32mInventory Complete
- pause >nul
- exit
- :: REM - Function that finds and logs files.
- :process_all
- :: REM - Increments counts used for display of chosen Information, Displays Status, Appends files found to log.
- For %%b IN (%1) DO (
- Set /a totalFiles+=1
- Set "name=%%~nb"
- Set "location=%%~dpb"
- Set "ext=!ext:.=!"
- Set "Storefile=!LogFilesDir!!ext!FILES!T_D!.log"
- ECHO [37m[1;1H[K [37m!totalFiles! [36mfiles logged in Total.
- ECHO [31m[2;1H[K Searching in !location!...
- ECHO [33m[3;1H[K !EXT! [37mfile: [34m!name! [0m
- ECHO(%%~b>>"!storefile!"
- )
- GOTO :eof
- :Get_DateTime
- Set T_D=%DATE%
- Set T_D=%T_D: =%
- Set T_D=%T_D%%TIME%
- Set T_D=%T_D:/=%
- Set T_D=%T_D::=%
- Set T_D=%T_D:.=%
- Set T_D=%T_D: =0%
- Set T_D=%T_D:~3,12%
- GOTO :EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement