Need to zip files and load into Source Modified Date , Date folder.

  • Hi,

    I have to zip files regularly and load them into destination, the destination folder should be in format YYYY_MM. How can I create folder in this format from source file modified date. Once I create this folder, then zip the files into this folder everyday without recreating this folder daily basis. I am using Execute process task to do this exercise. Any suggestions and ideas would be appreciable. 

    Many Thanks

    Sangeeth

  • Sangeeth878787 - Monday, October 30, 2017 1:42 AM

    Hi,

    I have to zip files regularly and load them into destination, the destination folder should be in format YYYY_MM. How can I create folder in this format from source file modified date. Once I create this folder, then zip the files into this folder everyday without recreating this folder daily basis. I am using Execute process task to do this exercise. Any suggestions and ideas would be appreciable. 

    Many Thanks

    Sangeeth

    1. Get modified date: use a Script Task
    2. Create folder: use either a Script Task or a File System Task
    3. Zipping files: use a Script Task or call an external command-line tool from an Execute Process task.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Hi 

    I am glad for your message, Being a newbie in SSIS, I am avoiding Script task for two reason, I don't know script and in my office laptap , i have got only  lastest version is .net 4.0 version.

    I have managed to zip all files in to one zip folder using Execute process task, but I am trying to achieve zip files into multiple zip Files based on the Year & Month.

    Eg Files:

    1)File1_20171001
    2)File2_20171002....
    31)File31_20171031
    32)File1_20171101

    Expected Output

    2017-10.zip Folder(In this folder the files need to be zipped, from File1_201701 to FileX_20171031)
    2017-11.zip Folder(November Month Files only).

    I had tried use expression task to create folder path and file name as YYYY_MM and passing this variable to Arguement in Process Task, 
     Its creating correct zip file name but all the files are compressed in both 2017_10 & 2017_11 Folders. Please could any one tell, how to provide this filter.

    Many Thanks

    Sangeeth

  • Scripting would be so much easier, especially if you can use a language like Python. I can provide you the example code if this is an option along with Python. You're talking like 5 lines of code to move, zip, and even create destinations based on the file name.

  • xsevensinzx - Monday, October 30, 2017 7:54 PM

    Scripting would be so much easier, especially if you can use a language like Python. I can provide you the example code if this is an option along with Python. You're talking like 5 lines of code to move, zip, and even create destinations based on the file name.

    I am very newbie to Python, but I am happy to give a try if this is pretty straight forward.could you provide me a code of it.

    Many Thanks

  • xsevensinzx - Monday, October 30, 2017 7:54 PM

    Scripting would be so much easier, especially if you can use a language like Python. I can provide you the example code if this is an option along with Python. You're talking like 5 lines of code to move, zip, and even create destinations based on the file name.

    I know that you're a fan of Python, but the implication that this is somehow complex or difficult to achieve in C# is just plain wrong. And all without the need for installing additional third-party tools.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Phil Parkin - Tuesday, October 31, 2017 5:40 AM

    xsevensinzx - Monday, October 30, 2017 7:54 PM

    Scripting would be so much easier, especially if you can use a language like Python. I can provide you the example code if this is an option along with Python. You're talking like 5 lines of code to move, zip, and even create destinations based on the file name.

    I know that you're a fan of Python, but the implication that this is somehow complex or difficult to achieve in C# is just plain wrong. And all without the need for installing additional third-party tools.

    I feel a challenge coming on! 😀

    I only say this because Python is just so abstract that Python can solve problems like this with fewer code and easier syntax that even a newbie to anything could implement. C#, not so much, but that does not make it bad. I could be wrong, but Python is just so dang easy for problems like this that it makes sense to at least consider it. That and the fact Microsoft is starting to incorporate it much more in the future.

    For example, just listing files in a directory:


    import os

    myFiles = os.listdir()
    print myFiles

    To something more precise:


    import os

    for files in os.listdir("C:/YourPath/"):
        if files.endswith('.zip'):
            print files
            # Do something else like, Unzip, Make Directory on File Name, etc

    Really simple stuff here.

  • xsevensinzx - Tuesday, October 31, 2017 5:52 AM

    Phil Parkin - Tuesday, October 31, 2017 5:40 AM

    xsevensinzx - Monday, October 30, 2017 7:54 PM

    Scripting would be so much easier, especially if you can use a language like Python. I can provide you the example code if this is an option along with Python. You're talking like 5 lines of code to move, zip, and even create destinations based on the file name.

    I know that you're a fan of Python, but the implication that this is somehow complex or difficult to achieve in C# is just plain wrong. And all without the need for installing additional third-party tools.

    I feel a challenge coming on! 😀

    I only say this because Python is just so abstract that Python can solve problems like this with fewer code and easier syntax that even a newbie to anything could implement. C#, not so much, but that does not make it bad. I could be wrong, but Python is just so dang easy for problems like this that it makes sense to at least consider it. That and the fact Microsoft is starting to incorporate it much more in the future.

    For example, just listing files in a directory:


    import os

    myFiles = os.listdir()
    print myFiles

    To something more precise:


    import os

    for files in os.listdir("C:/YourPath/"):
        print files
        # Do something else like, Unzip, Make Directory on File Name, etc

    Really simple stuff here.

    🙂
    Something similar in C#

       string[] fileEntries = Directory.GetFiles("c:\\temp");
        foreach (string fileName in fileEntries)
        {
          MessageBox.Show(fileName);
        }

    I'm not saying that it's simpler than Python ... C# syntax is tighter for sure. But once you learn the basics, it's just another language, and the physical amount of code is not that different.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Heh... "Basics".  "Script Tasks".  "Etc" 😉

    Speaking of "Basics", none of this is difficult using a couple of DOS commands and properly controlled use of xp_CmdShell (think "script task" but a whole lot easier).  No need for Python, C#, or much of anything else except a little knowledge and a copy of 7ZIP.  To coin a phrase, "When all it is that you're trying to do is drive a nail, use a hammer". 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply