I am trying to zip a Folder in SSIS, there are 12 files in the source folder and I need to zipthat folder. I can get the files to zip fine my problem is the folders.
I have to use winzip to create the zipped packages.
Can anyone point me to a good tutorial. I haven't been able to implement any of the samples that I have found.
Thanks
Adding a Script Task, yuo can use the ZipFile (class) here reference, you must refer to the System.IO.Compression.FileSystem assembly in the project (.NET Framework 4.5).
You need to provide to the Script Task the folder to be zipped and the name of the compressed folder as ReadOnlyVariables (to be added in the tab ReadOnlyVariables)
These two variables must be defined in the Variables tab (String type) of the package and can be changed dynamically through a cycle (eg. for each)
I use these two variables:
sFolderCompressed - the folder '.zip' that you want to obtain eg. C:\folder1\result.zip
sFolderSource - the source folder containing the files affected eg. C:\folder1\folder2
The script is made using c#, choose Script Language: Microsoft Visual C#
This is the code to be added in the Main method:
using System.IO.Compression;
public void Main()
{
try
{
string zipPath = (string)Dts.Variables["User::sFolderCompressed"].Value;
string startPath = (string)Dts.Variables["User::sFolderSource"].Value;
ZipFile.CreateFromDirectory(startPath, zipPath);
}
catch (Exception objException)
{
Dts.TaskResult = (int)ScriptResults.Failure;
// Log the exception
}
Dts.TaskResult = (int)ScriptResults.Success;
}
I hope can help.
Try using 7zip it is free. Take a look at 7zip command line user guide it contains all commands you need
And use a script task or an execute process task to achieve this. Also there are other useful links:
https://www.dotnetperls.com/7-zip-examples
UPDATE 1
you can follow this link for winzip:
http://www.vbforums.com/showthread.php?202918-Well-WinZip-Command-Line-Folders-to-Zip-keep-folder-structure-
In the link above they suggested using this command:
wzzip "c:\Test.zip" "c:\myfolder" -exPR
Write these things in bat file...
"C:\Program Files\WinZip\WINZIP64.EXE" -a "C:\Desktop\destination_folder\Sample.zip" "C:\Desktop\Sample"
In Execute process task:
Mention the location of bat file in Execute process Task-->Process-->Executable.
It's work fine.
Related
I have the following GDAL script using the OSGeo console that i have tested for one image, that I want to change now to run over every image in one folder and output to another folder?
Edit: the code I posted was a test I ran on one image to check visual quality. I was happy with the visual quality after compressing my test image. I now want to apply the script to approx. 1000 images located in one folder and output to another folder.
Edit: i am not sure why I have received a downvote for asking a question in a straightforward manner? I have checked numerous other posts on SO and reddit and have not been able to get any process to work within the QGIS OsGeo framework and would value some advice.
gdal_translate -co COMPRESS=JPEG -co PHOTOMETRIC=YCBCR -co TILED=YES "D:\split outputs\raster_compression test\EQ_GLNG_Photo_2018_MGA550.tif" "D:\split outputs\raster_compression test\0001_JPEG.tif" -scale -ot Byte
In the QGIS python console something like the following should work
This expects your input and output folders to exist, and it expects that the input folder contains all tif files as a child (not in sub folders)
import os
from osgeo import gdal
input_folder = 'path_to_input'
output_folder = 'path_to_output'
options = gdal.TranslateOptions(
outputType=gdal.GDT_Byte,
scaleParams=[''],
creationOptions=['COMPRESS=JPEG', 'PHOTOMETRIC=YCBCR', 'TILED=YES']
)
for entry in os.listdir(input_folder):
if entry.endswith('.tif'):
gdal.Translate(
os.path.join(output_folder, entry),
os.path.join(input_folder, entry),
options=options
)
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
I am working on creating a revit addin and I want to have it automatically pull a copy ofthe .dll and.addin files at shutdown using a batch file. By themselves the code and the batch file routines work correctly but when I have them running with each other I get a have a sharing violation for copying the .dll file. Can anyone tell me how I can get around the sharing violation? The purpose is to deploy these two files to all users and copy the file updates to their computer when they shut down Revit.
public Result OnShutdown(UIControlledApplication application)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "S:\\Revit 2015\\Addins\\Revit Tabs\\2015_RevitTab.bat";
proc.StartInfo.WorkingDirectory = "S:\\Revit 2015\\Addins\\Revit Tabs\\";
proc.Start();
return Result.Succeeded;
}
And here is the copy syntax
xcopy "S:\Revit 2015\Addins\Revit Tabs\Revit Tabs.addin" "C:\ProgramData\Autodesk\Revit\Addins\2015" /y
xcopy "S:\Revit 2015\Addins\Revit Tabs\Revit Tabs\bin\Debug\Revit Tabs.dll" "C:\ProgramData\Autodesk\Revit\Addins\2015" /y
You could add a call to your own stand-alone utility exe that monitors whether the current Revit process is still alive, and thenexecutes the add-in DLL copy process once Revit really is gone.
I wanted to same auto-update process and after a bit of trial and error I found some code that worked for me. Hopefully, you can use it or improve it.
I have ribbon.addin, ribbon.dll ("Ribbon") and commands.dll ("Commands") files. All files are installed as part of the deployment into the "%appdata%\Autodesk\Revit\Addins\2016" folder ("Local"). It's important that these are installed in the "%appdata%" folder and not the "%programdata%\Autodesk\Revit\Addins\2016" folder because of write protection issues!
The Ribbon addin is only for checking which version of the Commands is currently in the Local folder and if that's out-of-date from the Commands file I have in a shared network folder ("Shared"). Because of security, I can't read the AssemblyVersion of the Local DLL or the Shared DLL. To get around this I have a TXT file in the Local folder that has the AssemblyVersion as the first line and, in the Shared folder I have another TXT file (where I actually have the "About" information of the Commands addin) which has the Shared Commands AssemblyVersion as the first line.
So my Ribbon OnStartup(UIControlledApplication a) code checks the TXT files using System.IO.StreamReader. If the Local file is out-of-date it updates the Local TXT and DLL files with this c#:
try
{
string AddinsDir = a.ControlledApplication.CurrentUserAddinsLocation + #"\";
string tempDir = System.IO.Path.GetTempPath();
StreamWriter myStream = new StreamWriter(tempDir + "Commands.txt", false, System.Text.Encoding.Default);
myStream.WriteLine(AssemblyVersion);
//AssemblyVersion is the first line of the Shared Commands TXT file we read
myStream.Close();
File.Copy(tempDir + "Commands.txt", AddinsDir + "Commands.txt", true);
File.Delete(tempDir + "Commands.txt");
File.Delete(AddinsDir + "Commands.dll");
File.Copy(SharedPath + "Commands.dll", AddinsDir + "Commands.dll", true);
//SharedPath is the Shared folder
}
catch (Exception e)
{
TaskDialog.Show("Error Loading Ribbon", "There was an error loading the Ribbon. Please contact the BIM Manager for assistance.\n\n" + e.Message);
return Result.Failed;
}
If, at this point the code is still running the file is up-to-date and it's time to load it:
Assembly Commands = Assembly.LoadFrom(AddinsDir + "Commands.dll");
Type type = Commands.GetType("Commands.App");
//Commands.App is my class where my Ribbon is created and Events are registered
object instanceOfCommands = Activator.CreateInstance(type, new object[] { a });
return Result.Succeeded;
My plan for Revit 2017 deployment is to create my custom Ribbon in the Ribbon.dll so I can have my "About" button there and accessible at all times. Then, I'll add a button in the "About" dialog box that would manually update the Local Commands DLL.
I hope that helps!!
I have to scan a network drive of 120gb with over 100.000 folders. I am looking for .ini and .par files. My initial thought was to list all files from all directories and then throw out what i don't need.
I put a foreach loop with . on the whole drive, with in the loop an execute sql command where i do an insert into into a table with the full file name that was found.
I realize that writing to SQL for every record is a big performance issue, but have been unable to write it to an SSIS Object variable. It would be good to write to an In Memory table and only when the scan is finished, to push it all at once into the SQL database.
All ideas are welcome, if it's a solution to write to the SSIS object, good, if you have a better solution, very welcome.
SSIS will only be able to get a list of files on the network that exist in shared folders. Given this, you can do the following in a SSIS package to get a list of all of the files with a specific extension. The following example is based on the .ini file types. But you can easily add a second process in the same package for the .par files where the same two variables are reapplied.
Create an object variable called FileList and a string variable called File.
Create a script task to gather the .ini files where they are read from all subfolders and saved into an array. From there they are then saved into the object variable. Make certain it is defined in the ReadWrite part of the script when setting up.
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO;
namespace xxxxxx
{
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public void Main()
{
string[] ini_files = Directory.GetFiles(#"\\servername\sharedfolder", "*.ini", SearchOption.AllDirectories);
foreach (string name in ini_files)
{
Dts.Variables["User::FileList"].Value += name.ToString();
}
}
}
}
Create a Foreach Loop container applying the object FileList object variable in which each item saved to it is enumerated to the File string variable. From there just include in the container a SQL script or Data Flow task to save the contents to a database table.
This is just one of many ways to approach this task. The approach here is more modular while applying a fast method of gathering the files using C#.
Based on your comment that you don't have script task option, one of the approach I think of:-
1) You will need to create batch file with "dir %1 /s /b /o:n > %2" command to get the list of required list of names into some text file, where %1 and %2 are arguments.
2) You can add two different Execute Process Task into your package where you will add your batch file as Executable for both tasks and Arguments value will be "Z:*.ini,C:\tempSSIS\iniList.txt" for one and "Z:*.par,C:\tempSSIS\parList.txt" for other task.(assuming Z:\ is your network drive and second argument is file in which you would want to store the list of file names).
3) Then, you can add Data Flow Task after each Execute Process Task to read the text files and insert records into a same or different tables.
I wonder if anyone knows how to write a batch script to edit some text in a .cs file.
What I want to do is change "AssemblyVersion("1.0.0.0")" "AssemblyVersion("1.0.0.x")" where x++ for every time the job in jenkins is being built.
Best Regards Jan
Do you want to use only a batch script for this? You could also use Execute Groovy Script option and write some simple groovy script to achieve this
file = new File("folder/path/myfile.cs")
fileText = file.text;
fileText = fileText.replaceAll(srcExp, replaceText);
file.write(fileText);
You can also use the availabe environment variables from your jenkins job to construct your replace text. These variables will be present at /env-vars.html
Stay away from "batch-file automation" - will only cause you grief.
(for a starter, different versions of Windows support a different set of batch-commands)
You should incorporate the build-number in the script as an Environment Variable -
use either the "built-in" %BUILD_NUMBER% parameter or set your own format with
the Formatted Version-Number Plugin .
If you do need to edit that 'CS' file, I suggest using either Perl or PowerShell.
Cheers