Delete files from folder and sub folders - SSIS Package

  • I need to delete files from folder and sub folders. And also i shouldn't delete present hour data . I mean if i run the packag at 1.00 PM then it should not delete the files which generated at 1.00PM.

    I thought of writing batch files but may be SSIS script is better one. Please share the code. Thanks.

  • What we we do is, archive the files with datestamp to a different folder a first step and then copy the file to desired folder and ovewrite it. For both Filesystemtask in SSIS is very useful.

    VG

  • I shared this idea with my team but b/c of the Server space , we can't do like this. So can you share your code to delete files from folder and subfolder and also need to keep current hour data. It is very urgent for me since we are running out of space in our server.

    or Batch file also fine.

    Thanks a lot.

  • File system task can do this. Select either, delete file, delete directory, delete directory files according to your needs. I am not sure about the keeping only current files though...

    Are you sure you want to delete all files in folders and subfolders ?

    VG

  • No, I need to keep current hour files and delete all other files. It means if i run the package at 1.00PM then the package shouldn't delete the files which generated at 1.00PM. Files are generating every 2 mins.

    I have batch file to delete all the files from folder and subfolder. But i don't know how to keep current hour files. Even "forfiles" command also doesn't have keeping current hour files option. only have day.

    So , i am looking those kind of SSIS package or Batch file.

    Thanks for your immediate response.

  • u got this task done?? even I m waiting for the same task... please help me out if someone knows this....

  • We can do with Batch file with Delen command. I didn't try but someone sugges me. You can download Delen program from this link.

    http://delenxrd.adoxa.cjb.net

    Let me know .

  • I think we r not supposed to download these in production servers...But Thanks for the information...

  • We use the following to remove files x number of days old. I think it might work with hours, too.

    For days:

    forfiles /p C:\My Folder\ /s /m FilenamePrefix*.txt /d -7 /c "cmd /c del @path"

    Try this for hours:

    forfiles /p C:\My Folder\ /s /m FilenamePrefix*.txt /h -2 /c "cmd /c del @path"

    Give it a try. I hope it works for you.

  • Hey RML51..........could you please explain in detail...where I should use the command given by you...I have for each loop container and file system task...I created a user variable...I don't know what value should be given to the variable...

    Thank you

  • I just checked and unfortunately it doesn't look like it'll work with hours, only days.

    http://technet.microsoft.com/en-us/library/cc753551.aspx

    Sorry for the false hope.

  • Thanks for the reply....but where should we use this command? in the ssis package?? or cmd?? I m very novice in this...please don't mind...I just need to delete 15 days old files...

  • We run it in a .bat command file, and then execute that using scheduled tasks.

  • ok kool...now I got it...Thanks a lot...

  • Can you pls tell me any commans work with hours? I need to keep current 1 hr file and need to delete all other fils. Thanks.

Viewing 15 posts - 1 through 15 (of 15 total)

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