windows command promt zip/compress directory - archive

Is possible to compress/archive a directory with all of its sub-directories and files in a single file from cmd.exe ? I know there are a lot of utilities available but I need to perform the operation only with the windows default utilities . I'm running windows server 2003 .

Although the old makecab doesn't store a real directory structure, you can command the output directories for each file if you really need it. The procedure is more cumbersome than using a modern utility, but can be done.
For doing this you should create a .ddf file.
The manual for the old makecab has been removed from the web by MS. I found a copy here.
In page 33 of the makecab manual you will find:
DestinationDir=path
Path prefix to store in cabinet file for each file in the cabinet.
Default: .Set DestinationDir= ; Default is no path prefix
pathis concatenated with a path separator (“\”) and the target file name on
File Copy Commands to produce the file name that is stored in cabinet file.
EXTRACT.EXE will use this file name as the default name when the file is extracted.
Examples:
.Set DestinationDir=SYSTEM ; Following files get SYSTEM prefix
bin\ARIAL.TTF ; Name in cabinet is SYSTEM\ARIAL.TTF
.Set DestinationDir= ; No prefix
bin\ARIAL.TTF ; Name in cabinet is ARIAL.TTF
HTH!

There's really very little you can do as there's no command-line compression as part of Windows as standard.
The closest thing I can think of is to use the backup program NTBackup.
If there's any way you can install a utility I'd strongly recommend 7zip which I've had good experience of scripting with.

Related

Batch export in SAS for spk file

I need to export/import my spk file via windows Batch script.
For which I have been referring this document
But this document does not mention how to save the file (I mean with which extension .bat or .sas)
My command:
ExportPackage -profile "SAS_MW_TEST" -package "F:\mypath\Package4.spk" -objects "/_Applications/_05_MW/_01_SAS_MW/_20_Processes/savedesk(Folder)" -subprop -types "Condition,BusinessRuleFlow,ExternalFile,Cube,SearchFolder,Table,GeneratedTransform,OLAPSchema,InformationMap.OLAP,Measure,Column,Job.CubeBuild,Action,Library,MiningResults,DeployedJob,CalculatedMeasure,Hierarchy,InformationMap.Relational,RootFolder,Prompt,Document,ConditionActionSet,DecisionLogic,Dimension,Note,StoredProcess,PromptGroup,Job,OrchestrationJob,MessageQueue,Service.SoapGenerated,Level,SharedDimension,DeployedFlow"
ExportPackage is an executable program that you can run out of a batch file.
Use Notepad or any other text editor (which includes any SAS code editor), place the ExportPackage program command in the editor and use the File/Save As feature to save the file as something like myPackageExporter.bat
If the items in the package are say stored processes whose metadata says the source code is in an file system folder (aka source code repository), you will probably also want to zip up the folder.
This macro can help you prepare the batch script, ready for export: https://core.sasjs.io/mm__spkexport_8sas.html

Remove hex 1F from CSV file using Batch

I have multiple CSV files from different sites within my company that contain multiple names and email addresses from several SQL databases that many different company users enter data into. I have a SQL export program that exports the names and emails to CSV files. I have noticed that occasionally some of the email addresses have the hex 0x1F separator either before or after the email address (in Notepad++ it looks like a black "US" box).
How can I write a simple batch file to find and remove just that separator from any CSV file that may have it. And save the output using/replacing the original file. Preferably using simple batch commands, not Powershell or Java or anything else like that. This will be running on a standard install of Windows 2008 R2 without any extra programs added.
Example:
Directory:
C:\Uploads
Filenames (up to 23 files with a random 2 digit prefix followed by date):
"a1-20151101.csv", "b2-20151101.csv", "cd-20151101.csv", etc.
Inside CSV (FirstName;LastName;Email):
John;Doe;john.doe#johndoe.com
Jane;Smith;jsmith#google.com
You could spend precious time writing some 400-line behemoth of a cmd file.
Or you could simply go and get the tr program from GnuWin32 (ports of the popular UNIX tools to native Windows) which is perfectly suited to doing this sort of thing.
Then your batch file will basically consist of the line:
tr -d "\37" inputFile >outputFile
The tr program is contained within the coreutils package.

Rename a lot of files in subdirectories with multiple file extenisons

So I have a very big folder full of more folders which hold files that all have their regular extension, but then with ,v after it (like .xml,v)
Is there a quick way/program to make it go through all of the folders and when it finds a ,v it'll remove the ,v from it?
Thanks
EDIT: I am running Windows 7 (64-bit). Also please remember than I am an idiot :P
Use find to list the files ending ,v. Pipe the output to a shell loop that renames the files.
${f%%,v} matches the file name without the ,v suffix.
find . -name \*,v | while read f; do mv $f ${f%%,v} ;done
Not clear, Where you have the files? (In your computer / on a server).
What is the platform (Windows / Linux) ...
There are multiple ways to solve it based on scenario (like a tiny batch file can do it in a flash if the folder is in your local computer with windows platform) ...

Find multiple files from the command line

Description:
I am searching a very large server for files that is on a different server. right now I open command prompt and type
DIR [FILE NAME] /S/4
This returns the server location of the file with some other stuff that is not really needed.
Question:
I have a lot of files to search and one by one input into the above command could take forever. Is there a way I could input all of the names of all the files and only search once and the search results would only need to show file name and location?
First, I hope you don't mean DOS, but rather Windows cmd or batch.
You can certainly write a script that will run your DIR command once per file being sought.
But what you most likely want instead is to search once and print the path of each file found. For this you can use PowerShell's FindChildItem or the improved one posted here: http://windows-powershell-scripts.blogspot.in/2009/08/unix-linux-find-equivalent-in.html
It will be something like:
Find-ChildItem -Name "firstfile.txt|secondfile.txt|..."
Another approach is to install msys or cygwin or another Linux tools environment for Windows and use the Linux find command.

Is it possible to detect file format and encoding of file using batch files?

Is it possible to detect file format and encoding of file using batch files? And if a particular file is not of intended format, throw an error?
As a *nix guy, I'd want to jump for something more powerful than a batch file, such as Python. (or a shell script, but I'm assuming you're using Windows --- you might look into PowerShell, but I've never tried it.)
Unix has a great utility for this sort of thing, it's named file. There appears to be a Windows version here: http://gnuwin32.sourceforge.net/packages/file.htm
Basically, you run file [your filename here] and file spits out a blurb about the file. For example:
$ file zdoom-2.4.1-src.7z
zdoom-2.4.1-src.7z: 7-zip archive data, version 0.3
It's not always right, and it doesn't mean that if file says "this is a JPEG" that the file is actually a JPEG: it could be corrupt, etc.
Also, if I rename the above 7z archive to "foo":
$ file foo
foo: 7-zip archive data, version 0.3
... file will still get it.

Resources