1

I have a file share, and I want a process which enumerates files on that share and automatically creates a 7z self-extracting exe of files over 1 month old. On a different share, I want to create a 7z self-extracting exe of directories that are over 1 month old. Any idea if there is a program which can do this? I already have

7z a -t7z -mx9 -sfx filename.exe filename.txt 

Portion of it, just need more of the auto-management portion.

Running on Windows Server 2008, yes, PowerShell is available. Cygwin would not be an option.

2
  • Which operating system? I'm assuming Windows. If so, do you have access to Powershell? Jan 10, 2011 at 18:19
  • esac please edit your question qith a little more information about your system. Like Benjamin asked we need to know about operating system and whether you have things like powershell, cygwin, or other tool sets.
    – Caleb
    Jan 10, 2011 at 18:59

2 Answers 2

1

I ended up doing this with a batch file, and setting it to run via Task Scheduler. Here is the batch file if anyone is interested:

@echo off

set RETENTION_PERIOD_DAYS=30
set FILE_BASED_ARCHIVES=g:\shares\public\crashes
set DIRECTORY_BASED_ARCHIVES=g:\shares\results
set MINIMUM_FILESIZE=1000000
set ZIP_PATH="c:\Program Files\7-Zip\7z.exe"

if not {%1}=={} call :archive %1 %2 %3 %4&exit /b 0

echo Archiving files older than %RETENTION_PERIOD_DAYS% days.
echo File Based: %FILE_BASED_ARCHIVES%
echo Directory Based: %DIRECTORY_BASED_ARCHIVES%


for %%a in (%FILE_BASED_ARCHIVES%) do (
    echo ********* Archiving %%a
    du /s "%%a"
    echo  -----------------------
    forfiles /p %%a /s /m *.* /d -%RETENTION_PERIOD_DAYS% /c "cmd /c call ^0x22%~dpnx0^0x22 ^0x22FILE^0x22 ^0x22@isdir^0x22 ^0x22@fsize^0x22 @path"
    echo  -----------------------
    du /s "%%a"
    echo ****************************************************
)

for %%a in (%DIRECTORY_BASED_ARCHIVES%) do (
    echo ********* Archiving %%a
    du /s "%%a"
    echo  -----------------------
    forfiles /p %%a /d -%RETENTION_PERIOD_DAYS% /c "cmd /c call ^0x22%~dpnx0^0x22 ^0x22DIR^0x22 ^0x22@isdir^0x22 ^0x22@fsize^0x22 @path"
    echo  -----------------------
    du /s "%%a"
    echo ****************************************************
)



exit /b 0

:archive
    if /i "%~1"=="FILE" (
        if /i "%~2"=="FALSE" (call :archive_file %3 %4) else (echo Skipping %~4 as it is not a file.)
    )
    if /i "%~1"=="DIR" (
        if /i "%~2"=="TRUE" (call :archive_dir %4) else (echo Skipping %~4 as it is not a directory.)
    )
exit /b 0

:archive_file
    set FILESIZE=%~1
    if %FILESIZE% GEQ %MINIMUM_FILESIZE% (
        call :7zip %2 && del /q /f %2
    ) else (
       echo Skipping %~2 as it is smaller than %MINIMUM_FILESIZE% bytes.
    )
exit /b 0

:archive_dir
    call :7zip %1 && rd /q /s %1
exit /b 0

:7zip
    %ZIP_PATH% t "%~1">nul || (
        %ZIP_PATH% a -t7z -mx9 -sfx "%~dp1%~n1.exe" "%~dpnx1" || exit /b 1
    )
exit /b 0
0

Looks like he's running windows guys. (.exe)

Create a shortcut or batch file that runs the command, and then run the shortcut or batch file from Windows Task Scheduler.

2
  • 1
    That's not a hard-positive indicator as to which operating system being used. Yes, most of the time it is windows, but other operating system don't care what the extension is for executables. Nor does your response actually answer the question. With more information, a real answer could be provided. Jan 10, 2011 at 22:50
  • My apologies for not reading the question more thoroughly, though it looks like my answer guided him in the right direction.
    – goofology
    Jan 17, 2011 at 19:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .