按照 Noodles 的想法(当然你需要安装一些 .net 框架版本),你可以试试这个
(另存为trim.cmd
并调用为trim.cmd "fileToTrim.dat"
)
@if (@this==@isBatch) @then
@echo off
setlocal enableextensions disabledelayedexpansion
rem check arguments
set "fileToTrim=%~1"
if not exist "%fileToTrim%" goto :eof
rem search for a valid framework version
set "frameworks=%SystemRoot%\Microsoft.NET\Framework"
set "jsc="
for /f "tokens=* delims=" %%a in (
'dir /b /a:d /o:-n "%frameworks%\v*"'
) do if not defined jsc if exist "%frameworks%\%%a\jsc.exe" set "jsc=%frameworks%\%%a\jsc.exe"
if not defined jsc goto :eof
set "executable=%~dpn0.%random%.exe"
%jsc% /nologo /out:"%executable%" "%~f0"
if exist "%executable%" (
"%executable%" "%fileToTrim%"
del "%executable%" >nul 2>nul
)
endlocal
exit /b 0
@end
import System;
import System.IO;
var arguments:String[] = Environment.GetCommandLineArgs();
if (arguments.length > 1) {
var fi:FileInfo = new FileInfo(arguments[1]);
var fs:FileStream = fi.Open(FileMode.Open);
fs.SetLength (
Math.max(0, fi.Length - 1)
);
fs.Close();
};
这远没有效率,每次都编译jscript代码。最好直接写程序,编译使用。但只是作为一个例子......