Using MakeCab.exe & .ddf file (i.e. using directive file) how to specify destination cab filename? - windows

I have decided to use makecab.exe for my requirement to create cab files in my application.
http://msdn.microsoft.com/en-us/library/bb417343.aspx#microsoftmakecabusersguide
And I need to store files as per given path whether relative or absolute inside cab and extract files with original path preserved. So I will be using directive file for this and give that input to makecab command.
windows command promt zip/compress directory
But the cab output is stored in folder Disk1\1.cab.
Please help me to know how can I specify a desired cab filename as destination (I will take cab file name from user input)?
Also, is it possible to append more files to existing cab file in second run of makecab command?

Finally found the solution.
You can set following two variables in the directive file which will identify destination path and name of cab file:
DiskDirectoryTemplate=template [Output directory name template; * is replaced by disk number]
CabinetNameTemplate=template [Cabinet file name template; * is replaced by Cabinet number]
Description from Microsoft MakeCAB User's Guide
DiskDirectoryTemplate=template
Set the output directory name template. One directory is created for
each disk of the layout.
Default: .Set DiskDirectoryTemplate=DISK* ; Default is DISK1, DISK2,
etc.
As MakeCAB processes a directive file, it will create one or more
disk "images". Rather than using some specific disk format, however,
MakeCAB simply creates one subdirectory for each disk and places the
files for each disk in the appropriate directory. If a * exists in
this variable, then it is replaced with the disk number. If no * is
specified, then all files are placed in the single directory specified
by this variable.
This variable is used only if no variable DiskDirectoryn exists for
disk n.
Examples:
.Set DiskDirectoryTemplate=C:\EXCEL6\DISK* ; Put files in separate dirs
.Set DiskDirectoryTemplate=C:\EXCEL6 ; Put all files in C:\EXCEL6
.Set DiskDirectoryTemplate= ; Put all files in current dir
CabinetNameTemplate=template
Sets the cabinet file name template.
Default: .Set CabinetNameTemplate=*.CAB ; 1.CAB, 2.CAB, ...
This template is used to construct the file name of each cabinet. The *
in this template is replaced by the cabinet number (1, 2, etc.). This
variable is used only if no variable CabinetNamen exists for cabinet
n.
NOTE: Be sure that the expanded cabinet name does not exceed the
limits for your file system! For example, if you used "CABINET*.CAB",
and MakeCAB had to create 10 or more cabinets, then you would have
cabinet names like CABINET10.CAB, which is 9.3, which is an invalid
name in the FAT file system. Unfortunately, MakeCAB would not detect
this until it had already created 9 cabinets!
Examples:
.Set CabinetNameTemplate=EXCEL*.DIA ; EXCEL1.DIA, EXCEL2.DIA, etc.
.Set CabinetNameTemplate=*. ; 1, 2, 3, etc.
In addition, when files are split across cab (in case if cabinet size exceeds its limit size) then you can set subsequent cabinet filenames also using variable CabinetNamen:
CabinetNamen=filename [Cabinet file name for cabinet number n]
CabinetNamen=filename
The cabinet file name for the specified cabinet.
Default: ; By default none of these variables are defined
If this
variable is not defined for a particular disk, then MakeCAB uses the
CabinetNameTemplate to construct the cabinet name.
Example:
.Set CabinetName2=test2.cab

If you know exactly where your source files exist, you can generate a file list from the directory:
dir C:\FolderName /s /b /a-d > c:\temp\files.txt
Then use the files.txt file to create the cab file.
makecab /d CabinetName1=test.cab /D DiskDirectoryTemplate=C:\temp /f c:\temp\files.txt
The above command will generate a test.cab file in your C:\Temp folder using the file list generated earlier.
Additional helpful reference:
Microsoft Cabinet Reference. and
makecab.exe details.

Related

How to use MAKECAB.EXE

The syntax is:
MAKECAB [/Vn] [/D variable=value ...] [/L directory] source [destination]
MAKECAB [/Vn] [/D variable=value ] /F directives_file [...]
If no directives_file is used and the last parameter destination is specified, e.g. as "C:\Test", the cab will be generated in C:\Test.
But when a directives_file is used, the cab is generated in a subfolder \disk1.
What should be specified in the directives_file to have the same result as in the first case, i.e. the cab is generated in a specified folder?
I figured it out:
To get the cab with the name MyCabinet.cab in the folder C:\MyCabFiles, the following two lines must be included in the directives_file:
.Set CabinetName1="MyCabinet.cab"
.Set DiskDirectoryTemplate="C:\MyCabFiles"

Batch command XCOPY prompts me: Is the destination file or directory

When I run this file:
xcopy .\*.odt .\source.zip
I am prompted to specify what source.zip is:
xcopy .\*.odt .\source.zip
Does .\source.zip specify a file name
or directory name on the target
(F = file, D = directory)?
In my case when it find the .odt file to copy the file and place in the same directory but with new name source.zip. Is there approach to avoid the prompting since I always want destination to be a file not directory.
Any .odt file (being in .zip format in fact) is a binary file, see OpenDocument Document Representation
As a collection of several sub-documents within a package, each of which stores part of the complete document. This is the common
representation of OpenDocument documents. It uses filename extensions
such as .odt, .ott, .ods, .odp ... etc. The package is a
standard ZIP file with different filename extensions and with a
defined structure of sub-documents. Each sub-document within a package
has a different document root and stores a particular aspect of the
XML document. All types of documents (e.g. text and spreadsheet
documents) use the same set of document and sub-document definitions.
Therefore, you need to treat it as a binary file (read copy /?):
copy /B .\*.odt .\source.zip
Above command would work smoothly only if there will be only one file with extension .odt. Otherwise, it will prompt you for Overwrite .\source.zip? (Yes/No/All):. To stay on the safe side:
from command line for %G in (.\*.odt) do copy /B "%G" ".\source_%~nG.zip"
from a batch script for %%G in (.\*.odt) do copy /B "%%G" ".\source_%%~nG.zip"
%~nG (or in batch %%~nG) explanation: read Parameter Extensions.

Windows Batch - separate directory and filename from full file path string

I'd like to separate both a filename and a directory string from inside a full file path variable so i can refer to each separately later in a batch script.
Input Variable: SET "FULL=C:\test\file.txt"
Wanted Output:
FILE: file.txt
PATH: C:\test\
Currently the for loop & syntax is not making a whole lot of sense to me (in this batch scripting language) which is making it harder for me to find a working solution online...
set "FULL=C:\test\file.txt"
for %%a in ("%FULL%") do (
set "filePath=%%~dpa"
set "file=%%~nxa"
)
for loop will iterate over a set of files (only one file in set in this case), and for each of them the code after the do clause is executed.
For each iteration of the for loop and so for each execution of the do clause, the replaceable parameter (the %%a in the previous code) will hold a reference to the file being processed.
This replaceable parameter has some modifiers (that can be seen running for /?) to retrieve the required information from the file. The modifiers are in the form
%% ~ modifier replaceableParameter
In the previous sample code, d modifier is the drive where the file is stored, p is the path (folder hierarchy) where the file is stored, n is the file name without extension and x is the extension. So
%%~dpa = drive and path of the file being referenced by a
%%~nxa = name and extensions of the file being referenced by a

CMD to pick up specific files using a wild card

I have a CMD script I have been working on that reads a folder that has 3 different files in it. They have names like the following:
File1_ddmmyyyy.txt
File2_ddmmyyyy.txt
file3_ddmmyyyy.txt
I can use * to identify the files but the next step that uses the file name (Launching an ETL program) requires that the full file path. It is unable to identify the file (is entered as: file3_*.txt Literally)
Does anyone have and ideas on how I can grab this file based on the Wildcard, then obtain the full name to use later?
Thanks
EDIT - Example-
There is one ETL File executable line that matches up with each of the files based on the file name. for example:
File1_ddmmyyyy.txt is matched with ETL file File1.tf.map (Based on the file name and ETL file name) it is a one to one match (3 files to load and 3 ETL files to load them)
DJENGINE -sc "Y:\FileLocation\%Year_Mo_Da%\File1*.txt"-tc Server="X";Database="Y";Table="dbo.File1" "Y:\MapLocation\File1.tf.xml" (FileName = File1_ddmmyyyy.txt)
DJENGINE -sc "Y:\FileLocation\%Year_Mo_Da%\File2*.txt"-tc Server="X";Database="Y";Table="dbo.File2" "Y:\MapLocation\File2.tf.xml" (FileName = File2_ddmmyyyy.txt)
DJENGINE -sc "Y:\FileLocation\%Year_Mo_Da%\File3*.txt"-tc Server="X";Database="Y";Table="dbo.File3" "Y:\MapLocation\File3.tf.xml" (FileName = File3_ddmmyyyy.txt)
In the executable line of code for the ETL program instead of referencing the actual file name (Needed to run) it is trying to run File1*.txt Not filling in the variable.
My only thought would be since I have only 3 files and three ETL files that match base on the root file names I can place each of the files full names in a variable prior to this then use each of them in the executable ETL lines.
Not sure if this would work or how to do it. Let me know if this helps.
Hmm - started off clear as mud.
Then Taz arrived with his mixmaster on Turbo...
What congeals from this appears to be:
There's a directory "Y:\FileLocation\yyyy_mm_dd which contains 3 text files FileNddmmyyyy.txt
where dd is day number, mm month number, yyyy 4-digit year number and N will be 1..3.
The requirement from there is to build an appropriate command using the template
DJENGINE -sc "Y:\FileLocation\yyyy_mm_dd\FileN_ddmmyyyy.txt" -tc Server="X";Database="Y";Table="dbo.FileN" "Y:\MapLocation\FileN.tf.xml"
where dd,mm,yyyy,N have the same meanings, for N=1..3
#ECHO OFF
SETLOCAL
SET "yyyymmdd=%1"
IF NOT DEFINED yyyymmdd for /f "skip=1 delims=" %%x in ('wmic os get localdatetime') do set yyyymmdd=%%x&GOTO gotdate
:gotdate
SET "yyyymmdd=%yyyymmdd:~0,8%"&SET "yyyy=%yyyymmdd:~0,4%"&SET "mm=%yyyymmdd:~4,2%"&SET "dd=%yyyymmdd:~6,2%"
FOR %%a IN (1,2,3) DO ECHO(DJENGINE -sc "Y:\FileLocation\%yyyy%_%mm%_%dd%\File%%a_%dd%%mm%%yyyy%.txt" -tc Server="X";Database="Y";Table="dbo.File%%a" "Y:\MapLocation\File%%a.tf.xml"
GOTO :EOF
In the absence of any information about where yyyymmdd come from, the above should fill in the values for today.
If the procedure is provided with a parameter in the format yyyymmdd like this:
thisbatch 20140726
then the procedure will generate lines for July 26th 2014 (note that the value provided here is not checked for validity)
The required DJENGINE commands are merely ECHOed for testing purposes. After you've verified that the commands are correct, change ECHO(DJENGINE to DJENGINE to actually execute the program on the files. This presumes that DJENGINE is an executable, not a batch procedure.

Compress file to one cab file

I am currently trying to modify one file in a .cab file and then rebuild .cab file using 'makecab.exe' with all the files including the changed one. Following is the .ddf file, I am using.
.Set CabinetNameTemplate=Documents.CAB
.Set Cabinet=on
.Set Compress=on
"00000000.000"
"10000000.000"
"20000000.000"
"30000000.000"
"40000000.000"
"manifest.xml"
The problem is that three files are generated stored in disk1,disk2 and disk3 folders. The files are trimmed to <1424kb. I want a single cab file. I have tried setting the threshold and size variables.
I encountered same problem today and luckily I found solution in Microsoft page.
(http://msdn.microsoft.com/en-us/library/bb417343.aspx#microsoftmakecabusersguide)
You can add maxdisksize option in .ddf file and it will work!
.Set MaxDiskSize=CDROM

Resources