Abstand bei Pfad-Variable in batch-Skript?

ruutaiokwu

Top Contributor
Was muss ich tun bei `dSource` ?

Bringt nix:

1. set dSource="G:\Meine Ablage\git-backup"

oder

2. set dSource=G:\Meine Ablage\git-backup
for /f "delims=" %%f in ('dir /a-d-h-s /b /s "%dSource%"') do (


@echo on
setlocal ENABLEDELAYEDEXPANSION
set day=86400
set /a year=day*365
set /a strip=day*7
set dSource=G:\Meine Ablage\git-backup

call :epoch %date%
set /a slice=epoch-strip

for /f "delims=" %%f in ('dir /a-d-h-s /b /s %dSource%') do (
call :epoch %%~tf
rem if !epoch! LEQ %slice% (echo DELETE %%f ^(%%~tf^)) ELSE echo keep %%f ^(%%~tf^)
if !epoch! LEQ %slice% del /f %%f
)
exit /b 0

rem Args[1]: Year-Month-Day
:epoch
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=1,2,3 delims=-" %%d in ('echo %1') do set Years=%%d& set Months=%%e& set Days=%%f
if "!Months:~0,1!"=="0" set Months=!Months:~1,1!
if "!Days:~0,1!"=="0" set Days=!Days:~1,1!
set /a Days=Days*day
set /a _months=0
set i=1&& for %%m in (31 28 31 30 31 30 31 31 30 31 30 31) do if !i! LSS !Months! (set /a _months=!_months! + %%m*day&& set /a i+=1)
set /a Months=!_months!
set /a Years=(Years-1970)*year
set /a Epoch=Years+Months+Days
endlocal& set Epoch=%Epoch%
exit /b 0
 

ruutaiokwu

Top Contributor
Wieder nix:

G:




cd \
cd "Meine Ablage"
cd git-backup




call :epoch %date%
set /a slice=epoch-strip


for /f "delims=" %%f in ('dir /a-d-h-s /b /s .') do (
call :epoch %%~tf
rem if !epoch! LEQ %slice% (echo DELETE %%f ^(%%~tf^)) ELSE echo keep %%f ^(%%~tf^)
if !epoch! LEQ %slice% del /f %%f
)
exit /b 0


Dito:

G:
cd \
cd "Meine Ablage"
cd git-backup




call :epoch %date%
set /a slice=epoch-strip


for /f "delims=" %%f in ('dir /a-d-h-s /b /s @Path') do (
call :epoch %%~tf
rem if !epoch! LEQ %slice% (echo DELETE %%f ^(%%~tf^)) ELSE echo keep %%f ^(%%~tf^)
if !epoch! LEQ %slice% del /f %%f
)
exit /b 0
 

ruutaiokwu

Top Contributor
Klappt auch nicht, jedenfalls sind nach dem Ausführen noch immer 8 Dateien drin:

C:
cd \
cd Tools
cd git-backup
@echo off
setlocal
set sourceDir=C:\_GIT
set zipFile=git-backup-%date:~-4%_%date:~3,2%_%date:~0,2%__%time:~0,2%_%time:~3,2%_%time:~6,2%.zip
echo Add-Type -A System.IO.Compression.FileSystem >> %~dp0TempZipScript.ps1
echo [IO.Compression.ZipFile]::CreateFromDirectory('%sourceDir%','%~dp0%zipFile%') >> %~dp0TempZipScript.ps1
PowerShell.exe -ExecutionPolicy Bypass -Command "& '%~dp0TempZipScript.ps1'"
del %~dp0TempZipScript.ps1
move *.zip "G:\Meine Ablage\git-backup"
cd "G:\Meine Ablage\git-backup"


rem J.M., 2019-12-24 {
for /f "usebackq delims=" %%G in (
`forfiles /c "cmd /c if /i @isdir == true echo @Path" /d 7 2^>nul`
) do echo del "%%~G"
rem } J.M., 2019-12-24


rem C:\Tools\git-backup\clean.bat


setlocal
endlocal & exit /b
 

Ähnliche Java Themen

Neue Themen


Oben