Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.6 kB
2
Indexable
Never
@echo off
setlocal enabledelayedexpansion

:: Check if any file was dragged onto the script
if "%~1"=="" (
    echo Please drag and drop a file onto this batch script.
    pause
    exit /b
)

:: Process each file passed as an argument
for %%F in (%*) do (
    echo Processing file: %%F
    if exist "%%F" (
        :: Create a temporary file to store cleaned content
        set "temp_file=%%~dpF%%~nF_cleaned%%~xF"
        
        set "in_block_comment=false"

        :: Open the file for reading
        >"!temp_file!" (
            for /f "usebackq delims=" %%L in ("%%F") do (
                set "line=%%L"
                
                :: Check for the start of a block comment (/*)
                echo !line! | findstr /r ".*\/\*.*" >nul
                if not errorlevel 1 (
                    set "in_block_comment=true"
                )

                :: Check for the end of a block comment (*/)
                echo !line! | findstr /r ".*\*\/.*" >nul
                if not errorlevel 1 (
                    set "in_block_comment=false"
                    continue
                )

                :: Add line if it's not inside a block comment
                if "!in_block_comment!"=="false" (
                    echo !line! | findstr /r ".*\/\*.*" >nul
                    if errorlevel 1 echo !line!
                )
            )
        )

        :: Replace the original file with the cleaned one
        move /y "!temp_file!" "%%F" >nul
        echo File cleaned: %%F
    ) else (
        echo File not found: %%F
    )
)

pause
Leave a Comment