Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
miskox
- Posts: 630
- Joined: 28 Jun 2010 03:46
#1
Post
by miskox » 27 Oct 2017 08:17
Hello all!
Is there a simple way to identify if a file is Micrsoft Cabinet file (first four bytes are 'MSCF'):
Code: Select all
@echo off
REM (Windows XP version of expand)
dir >test.zip
REM expand should list files in the archive if OK
expand -D test.zip
echo ERRORLEVEL=%errorlevel%
Output:
Code: Select all
c:\>a.cmd
Microsoft (R) File Expansion Utility Version 5.1.2600.0
Copyright (C) Microsoft Corp 1990-1999. All rights reserved.
test.zip: test.zip
ERRORLEVEL=0
c:\>
As you can see expand does not report any errors.
So probably the best way would be to check first four bytes of a file. But this can take some time unless you guys have a quick solution.
Thanks.
Saso
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#2
Post
by aGerman » 27 Oct 2017 09:50
You can use FC /B to hex-dump the first few bytes. But maybe it's also sufficient for you to do a textual comparison.
Untested:
Code: Select all
@echo off &setlocal
set "file=test.zip"
setlocal EnableDelayedExpansion
<"!file!" set /p "somebytes="
if "!somebytes:~,4!" neq "MSCF" exit /b
endlocal
:: your code here ...
Steffen
-
miskox
- Posts: 630
- Joined: 28 Jun 2010 03:46
#3
Post
by miskox » 27 Oct 2017 10:12
Thanks Steffen!
This works.
Saso