Stuck on overwrite question unzipping files

Hi guys!
I've created a script that extract zip files (7z and zip extensions) but i've got a problem with overwriting.
Clear-Host
Function Find-Files(){
[CmdletBinding()]
param(
[Parameter(Mandatory=$true,Position=0)][string]$Path,
[Parameter(Mandatory=$true,Position=1)][string]$Code
$Test=0
$WorkFiles=@()
$Unzipped=@()
$AllFiles=Get-ChildItem -Path $Path -Recurse -File
foreach( $item in $AllFiles|Where{ $_.Name -like "sin*.dat" } ){
$WorkFiles+= $item.FullName
$ZipFiles=$AllFiles|Where{($_.Extension -eq ".7z") -or ($_.Extension -eq ".zip")}
if( $ZipFiles.Length -ne 0 ){
$Test=1
Set-Alias 7zip "$env:ProgramFiles\7-Zip\7z.exe"
$Directory="D:\ZTemp"
if((Test-Path $Directory) -eq $false){
mkdir $Directory
foreach ($Zip in $ZipFiles){
$Name=$Zip.BaseName
$Destination=$Directory,$Name -join('\')
if( Test-Path $zip.Name ){
Write-Error "Sono presenti Cartelle compresse con nomi uguali $Destination" -Category SecurityError
$Unzipped+= $Zip.FullName
$foreach.movenext()
#continue
cd $Zip.Directory.FullName
7zip 'x' $Zip.Name "-o$Destination"
$ExtFiles= Get-ChildItem $Destination -File -Recurse|Where-Object{ $_.Name -like "sin*.dat"}
if ($ExtFiles.count -eq 0){
Remove-Item $Destination -Recurse -Force
else{
foreach ($item in $ExtFiles){
$WorkFiles+=$item.FullName
cd $env:HOME
$i=2
$Pattern="Total Cutting Time for Each Tool"
$Excel = New-Object -ComObject excel.application
$Excel.visible=$false
$WorkBook= $Excel.workbooks.add()
$WorkSheet= $WorkBook.worksheets.item(1)
$WorkSheet.cells.item(1,1)="Codice"
$WorkSheet.cells.item(1,2)="Quantità"
$WorkSheet.cells.item(1,3)="Progetto"
$WorkSheet.cells.item(1,4)="N° elementi"
$WorkSheet.cells.item(2,4)=$WorkFiles.Length
foreach ($item in $WorkFiles){
$Breaches=(Select-String -Path $item -Pattern "not Used").LineNumber
$Line=(Select-String -Path $item -Pattern $Pattern).LineNumber
$Lines=(Select-String -Path $item -Pattern $Code).LineNumber
$Count=0
foreach ($Number in $Lines){
if($Number -gt $Line){
$Count=$Count+1
if( $Breaches -ne $null ){
if($Number -eq $Breaches[0]){
$Count-=1
if($Number -eq $Breaches[1]){
$Count-=1
$Count=$Count/2
$Project=((Select-String -Path $item -Pattern "Project Definition").Line -split(':'))[1]
$WorkSheet.cells.item($i,1)=$Code
$WorkSheet.cells.item($i,2)=$Count
$WorkSheet.cells.item($i,3)=$Project
$i=$i+1
$Excel.Cells.EntireColumn.AutoFit()
$WorkBook.saveas("get-files",51,[Type]::Missing,[Type]::Missing,$false,$false,1,2)
$WorkBook.close()
$Excel.quit()
if ($Test -eq 1){
Remove-Item $Directory -Recurse
Write-Output "Procedura Conclusa con Successo"
function Button ($Title,$Path, $Code) {
[void][System.Reflection.Assembly]::LoadWithPartialName( “System.Windows.Forms”)
[void][System.Reflection.Assembly]::LoadWithPartialName( “Microsoft.VisualBasic”)
#####Define the form size & placement
$form = New-Object “System.Windows.Forms.Form”;
$form.Width = 500;
$form.Height = 150;
$form.Text = $title;
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen;
##############Define text label1
$textLabel1 = New-Object “System.Windows.Forms.Label”;
$textLabel1.Left = 25;
$textLabel1.Top = 20;
$textLabel1.Text = $Path;
##############Define text label2
$textLabel2 = New-Object “System.Windows.Forms.Label”;
$textLabel2.Left = 25;
$textLabel2.Top = 55;
$textLabel2.Text = $Code;
############Define text box1 for input
$textBox1 = New-Object “System.Windows.Forms.TextBox”;
$textBox1.Left = 150;
$textBox1.Top = 10;
$textBox1.width = 200;
############Define text box2 for input
$textBox2 = New-Object “System.Windows.Forms.TextBox”;
$textBox2.Left = 150;
$textBox2.Top = 50;
$textBox2.width = 200;
#############Define default values for the input boxes
$defaultValue = “”
$textBox1.Text = $defaultValue;
$textBox2.Text = $defaultValue;
#############define OK button
$button = New-Object “System.Windows.Forms.Button”;
$button.Left = 360;
$button.Top = 85;
$button.Width = 100;
$button.Text = “Ok”;
############# This is when you have to close the form after getting values
$eventHandler = [System.EventHandler]{
$textBox1.Text;
$textBox2.Text;
$form.Close();};
$button.Add_Click($eventHandler) ;
#############Add controls to all the above objects defined
$form.Controls.Add($button);
$form.Controls.Add($textLabel1);
$form.Controls.Add($textLabel2);
$form.Controls.Add($textBox1);
$form.Controls.Add($textBox2);
$ret = $form.ShowDialog();
#################return values
return $textBox1.Text, $textBox2.Text.ToUpper()
$return= Button “Ricerca Codici” “Enter Path” “Enter Code”
$StartDTM=Get-Date
Find-Files -Path $return[0] -Code $return[1]
$EndDTM=Get-Date
"Elapsed Time: $(($EndDTM-$StartDTM).totalseconds) seconds"
 launching this script i'm stuck here:
Please tell me how to go ahead with this problem.
Thanks
A

This is a 7Zip command issue.  You need to set the zip command correctly.  If you do not know how to use 7zip then post in the 7zip forum.
You can get the arguments from 7zip "7z /?"
¯\_(ツ)_/¯

Similar Messages

  • Question - unzipping files

    When saving files many of them seem to get zipped. When I click on them to try and open them there is a momentary flash and then the zip appears as before. How do I open these files? Mart Bi

    This is a 7Zip command issue.  You need to set the zip command correctly.  If you do not know how to use 7zip then post in the 7zip forum.
    You can get the arguments from 7zip "7z /?"
    ¯\_(ツ)_/¯

  • Very basic question... can photoshop overwrite the original file?

    Very basic question... can Photoshop Elements 13 overwrite the original file?

    You will need to check the Photoshop Elements for any particulars about that software.
    For Photoshop, if I make changes and exit saving those changes, yes the original is overwritten.
    Keep backups at all times and don't work off flash external drives. When people tell me their original 500 layer file got corrupted, and they didn't keep copies, I hate to tell them their weeks of work is down the bucket.
    In Photoshop, we use Image > Duplicate to work on a copy if we don't want the original touched, or File > Save as... where we give the file a different name. We save image.psd as image1.psd and image.psd is closed. We then have a copy, "Image1" opened.
    Gene

  • Unable to unzip files , unable to move apps into the app foldercant update

    I cannot unzip files. Also if i try to install a new app by dragging it to the applications folder it says "that files already exists".
    also if i try to update with software update it gives an error. i tried running verify disk permissions and repair disk permissions but this did nothing please help i am scared cuz my last time machine was along time ago.

    Not to worry.
    A few clarification questions first.
    What exactly does the dialog say when you try to drag a new app to the applications folder? Is it something like, "an older version of this already exists in this location, do you want to replace it with the version you are moving?"
    And, what application are you attempting to use to unzip files?

  • Unzip file from froms then load

    i have form (basically called loader) which read text file and then load it in data base.
    Now,there is a user requirement that if text file is in zip format then he can unzip file using form.
    Any idea how to do this can some unzip software used at back end.
    I mean any idea any suggestion is required.
    Forms 6i i am using.

    The zip.exe and unzip.exe are shipped with Oracle products, they are found under %ORACLE_HOME%/bin
    just type zip or unzip in a command line session and you'll get all the switches and details.
    Judging from your first post I understand you are running in C/S mode, if not you need to use CLIENT_HOST from webutil instead of HOST. It's the same concept.
    As for HOST built-in example, I told you, there are very nice and detailed examples in the online help of Forms builder.
    Open Forms builder and either press Ctrl + H or click on the big blue question mark, or open help menu and click on "Online Help".
    Tony
    Message was edited by:
    Tony Garabedian

  • Unzip files from a folder which is updating regularly using multithreading

    Hi All,
    I have acode which unzip all the files from a folder .This code picks up all the zipped files at a time and then unzip it and write them to another folder but now my requirement is changed ,suppose the source folder where all the zipped files are present is refreshed or updated with new zipped files regularly then how can I implement in my code multithreading to get several files by threads and send it for unzipping.
    Please suggest with some example or edit my code.
    package com.myprojcet;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipInputStream;
    public class Main {
         * Extracts a zip file
         public void extractZipFile() {
              try {
                   String zipFileName = "C:\\soft\\test"; //Source folder for zipped files
                   //Create input and output streams
                   File SourceDir = new File(zipFileName);
                   File[] zipFiles = SourceDir.listFiles();
                   ZipInputStream inStream = null;
                   OutputStream outStream = null;
                   ZipEntry entry;
                   byte[] buffer = new byte[1024];
                   int nrBytesRead;
                   //Get next zip entry and start reading data
              for(int i=0; i < zipFiles.length; i++) {
                   inStream= new ZipInputStream(new FileInputStream(zipFiles));
                   while((entry = inStream.getNextEntry()) != null) {
                        outStream=new FileOutputStream("C:\\soft\\test2\\"+entry.toString()); //destination folder for unzipped file
                        while ((nrBytesRead = inStream.read(buffer)) > 0) {     
                             outStream.write(buffer, 0, nrBytesRead);
                   //Finish off by closing the streams
                   outStream.close();
                   inStream.close();
              } catch (IOException ex) {
                   ex.printStackTrace();
         * @param args the command line arguments
         public static void main(String[] args) {
              new Main().extractZipFile();
    Thanks
    Sumit
    Edited by: user8687839 on Feb 27, 2012 11:00 PM

    But my question is that if in a source folder we have several files which are in zipped format and the folder is getting updated every min (say) with new zipped files (which are dumped from some outside environment).I need to unzip all the files present in the folder ,if new one comes there then also check for the new zipped file and unzip it.You don't need to keep re-stating that.
    I had written a code for unzipping a file from a folder (thinking the folder is not updated everytime).Or that.
    Now I am thinking of using threads because if I create suppose 5 threads and every threads poll the source folder and pick up a zip file ,send it for unzipping it and again poll the source folder for any new entries?Or that.
    If using the threads here hits performace then what should I use?Err, what you presently have?
    Provide me any sample code or link that would be more useful.You've already written it.

  • Execute Process Task error-Unzip Files

    Dear All,
       I have a SSIS package, that downloads a Zip file from FTP Server and extract and load that information in Sql Server Table. In my case every time I have only one file in FTP Server. There is no possible to get multiple files from FTP Server.
    While at the time of executing SSIS package getting error at Execute Process Task(Unzip Files) i.e 
    Error Description :In Executing "F:\7z\7z.exe" " x F:\ZipFiles\Sales_010815.zip -oF:\ZipFiles\" at "", The process exit code was "2" while the expected was "0".
    This error message getting while unzip my file. 
    Can some one help on this issue.
    Regards,
    Praveen C.
    Regards, Praveen

    Hi Praveen,
    After testing the issue in my environment, I find the issue is caused by the code in Arguments is incorrect.
    To fix this issue, please refer to the code below:
    x F:\ZipFiles\Sales_010815.zip -oF:\ZipFiles
    The following screenshot is for your reference:
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Unzip files from SDCARD

    HI,
    i am trying to unzipping files from external sdcard..
    i am using zipme.jar, but when i am deploying this application it give error.
    please nay one hep me to unzipping files using 3rd-party jar

    But my question is that if in a source folder we have several files which are in zipped format and the folder is getting updated every min (say) with new zipped files (which are dumped from some outside environment).I need to unzip all the files present in the folder ,if new one comes there then also check for the new zipped file and unzip it.You don't need to keep re-stating that.
    I had written a code for unzipping a file from a folder (thinking the folder is not updated everytime).Or that.
    Now I am thinking of using threads because if I create suppose 5 threads and every threads poll the source folder and pick up a zip file ,send it for unzipping it and again poll the source folder for any new entries?Or that.
    If using the threads here hits performace then what should I use?Err, what you presently have?
    Provide me any sample code or link that would be more useful.You've already written it.

  • Unzipping Files in the wrong folder

    Hi
    I am trying to unzip files. It works fine except that it unzips the files at the root. So i have tried specifying the path for making the directory (in which the unzipped files are stored). But that doesnt seem to work. Now i am unable to find the unzipped files. CAN ANYONE HELP PLEASE
    public static void unzipFile(String zFile)
            Enumeration entries;
            ZipFile zipFile;
           try {
                zipFile = new ZipFile(zFile);
                File file = new File(zipFile.getName());
                String fname = file.getName();
               String substr1 = fname.substring(0, fname.indexOf("."));
                String filepath = "/data/psawant/temp";
                File dir = new File(filepath, substr1);
                try {
                        dir.mkdir();
                catch (Exception fe)
                      System.err.println("Unhandled exception:");
                        fe.printStackTrace();
                        return;
                entries = zipFile.entries();
                while(entries.hasMoreElements()) {
                    ZipEntry entry = (ZipEntry)entries.nextElement();
                    if(entry.isDirectory())
                         // Assume directories are stored parents first then children.
                        System.err.println("Extracting directory: " + entry.getName());
                                          (new File(entry.getName())).mkdir();
                        continue;
                    } //end of if
                    System.err.println("Extracting file: " + entry.getName());
                    copyInputStream(zipFile.getInputStream(entry),
                        new BufferedOutputStream(new FileOutputStream(entry.getName())));
                 } //end of while
                zipFile.close();
                   } catch (IOException ioe)  {                 }
             } //end of unzip function
    public static final void copyInputStream(InputStream in, OutputStream out)
        throws IOException
            byte[] buffer = new byte[1024];
            int len;
            while((len = in.read(buffer)) >= 0)
            out.write(buffer, 0, len);
            in.close();
            out.close();
    Any help is apprciated
    Thanx

    Sorry I got it this time. I had overlooked the new File. I added that & it works fine but there seems to be some problem
    If the folder has another folder inside . it doesnt show that one. or rather just unzips one folder & no folders inside it. But i guess i can check for that
    Thanx for u r help
    Have a nice day

  • UNZIP file from ABAP

    Hi,
    I have a requirement to retrieve a zip file from the FTP Server, unzip it to the SAP Server and process the unzipped files. Retrieving the data from the FTP server should work via FTP commands which can be executed from within an ABAP program. However, the problem is unzipping these files via ABAP and put them on the server as well. 1. How to do this from within an ABAP Program? (unix commands?)
    2. Can I unzip these files with or without using the folder structure? (additional parameter for unix command?)
    Kind regards,
    Micky.

    REPORT ZTESTUNIX line-size 400
                    no standard page heading.
    selection-screen begin of block ucmd with frame title text-001.
    parameters: unixcom like   rlgrap-filename.   " ...SAP Interface file
    selection-screen end of block ucmd.
    data: begin of tabl occurs 500,
            line(400),
          end of tabl.
    data: lines type i.
    start-of-selection.
      refresh tabl.
      call 'SYSTEM' id 'COMMAND' field unixcom
                    id 'TAB'     field tabl[].
      describe table tabl lines lines.
      loop at tabl.
        write:/01 tabl-line.
      endloop.
      skip 2.
      if lines = 0.
        write:/ 'NO Occurances were found'.
      else.
        write:/ 'Command was successfully executed' color col_total.
        write:/ 'Number of entries in Search' color col_total,
                 lines color 6.
      endif.
    end-of-selection.
    while running give the command as
    <b>unzip test.zip  -x dir</b>
    then it will unzip test.zip file to dir called dir.
    you can specify the filepath instead of file...
    regards
    vijay

  • How to overwrite  the xml file by  flash using Php

    Hi
    i am creating getting data from the xml file ... and i am
    doing some Alteration in the xml file by flash after that flash
    producing the xml file i finished upto this process...
    nw i neeed to overwrite the xml file.... using Php.....
    can any one give me some idea ... to solve this issue
    ~~SK

    Flash Player cannot write XML files at all. but using
    php+flash we could do it .

  • Question on File Content Conversion

    Hi all,
       I went through this blog(/people/venkat.donela/blog/2005/03/02/introduction-to-simplefile-xi-filescenario-and-complete-walk-through-for-starterspart1) for File content conversion and I have a question regading File Content Conversion. Is it always neccessary to have the data type structure as File, Record, Row and then the fields. Is it always neccesary to maintain this level of hierarchy for File content conversion to work.

    Hi Sonia,
    For FCC sender or receiver if you want text with delimieter / csv file process.
    use the below parameters
    You would have to use the Document name ,namespace,record set name ,record strucutre name ( and occurrences also) and processing parameters in Sender side
    In receiver side Record structre, processing parameters.
    see below links to have more details..
    /people/michal.krawczyk2/blog/2004/12/15/how-to-send-a-flat-file-with-fixed-lengths-to-xi-30-using-a-central-file-adapter
    /people/jeyakumar.muthu2/blog/2005/11/29/file-content-conversion-for-unequal-number-of-columns
    /people/anish.abraham2/blog/2005/06/08/content-conversion-patternrandom-content-in-input-file
    /people/harrison.holland5/blog/2006/12/20/xi-configuration-for-mdm-integration--sample-scenario /people/shabarish.vijayakumar/blog/2006/04/03/xi-in-the-role-of-a-ftp
    /people/prateek.shah/blog/2005/06/14/file-to-r3-via-abap-proxy
    /people/mickael.huchet/blog/2006/09/18/xipi-how-to-exclude-files-in-a-sender-file-adapter -
    Regards
    Chilla

  • Problem with unzipping file

    I am trying to unzip a file using java.util.zip. It is throwing a ZipException in the first line where I instantiate ZipFile object.
    ZipFile oFile = new ZipFile("/myzip.zip");java.util.jar is not working either. It fails right here:
    JarFile oFile = new JarFile("/myzip.zip");Here is the exception thrown in the above cases:
    java.util.zip.ZipException: error in opening zip file
            at java.util.zip.ZipFile.open(Native Method)
            at java.util.zip.ZipFile.<init>(Unknown Source)
            at java.util.jar.JarFile.<init>(Unknown Source)
            at java.util.jar.JarFile.<init>(Unknown Source)
            at ReadZipFile.main(ReadZipFile.java:21)
    An interesting observation:
    I am able to extract the contents of the zip from the command-line using jar utility.
    jar xvf myzip.zipI am stumped! I think jar utility internally uses the same classes for unzipping files. How come it is working with jar utility whereas it is not working from Java program? Also, the myzip.zip appears to be a valid archive - I am able to open it with winzip.
    Any pointers will be appreciated.
    Thanks in advance,
    Ganesh

    I think the above reply is correct but didn't explain why you would be getting a file not found. Unless you have your zip file at the root of your harddrive the slash in the filename is improper. Without the slash your code will assume your current working directory and look for the file there.
    By putting that forward slash in there you are telling the code to look at the root of the filestructure and NOT at the current working directory.

  • Unzip files from FTP using  ABAP

    Hi All,
    I have the a requirement to unzip certain files from ftp and transfer the extracted files to another directory in ftp.
    Searched  (Re: Unzip file;)  in SDN but didnt find the perfect solution
    Appreciate the help.
    Regards
    Siva

    You can use IndexOf function
    see this example
    http://visakhm.blogspot.in/2012/05/package-to-implement-daily-processing.html
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Overwriting a PDF file that is open on another computer

    Hi!
    Instead of a intranet, we decided to post a PDF file via network mapping to keep the staff updated on the latest news.
    We use a mapped network folder as source for the documents, and one document with links so the staff can navigate to relevant information. The staff opens the PDF-file in IE.
    The problem we have is that whenever someone in the staff has opened the document in IE we are unable to edit the PDF in Word and overwrite the PDF-file that are availible to the staff.
    Is there any way that we can make the file overwritable when someone has opened it, and the person that is reading the file can simple refresh and get the updated information?
    This document will be edited by several departement managers, so it's impossible for us to use other editing tools than Office  (which they are already used to).
    Thanks in advance.

    I'm not an expert on editing files that are opened by another application, but I am not sure it _can_ be done the way you currently have it set up.  At least as far as IE is concerned.  (And I hate IE, too.. never did like it.)
    IMHO, the file should be stored in a database; that way, no matter how many people are accessing it, you can make changes and save them to the binary stored in a BLOB/CLOB datatype.  And if you (exclusive) lock the record as it's being saved, whomever is trying to access it will be "paused" until the save is complete and they will then retrieve the latest update without any corruption of data, or other 'hiccup'.
    If a database is not an option, I'm not sure what to do.  If it were an intranet, it might be different.  But a network share isn't the best solution.  It might be cost-saving or easier to maintain; but there's a saying - You can have it cheap, fast, or good; pick two.
    ^_^

Maybe you are looking for