How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask ehabtutor Your Own Question

ehabtutor
ehabtutor, Computer Software Engineer
Category: Programming
Satisfied Customers: 1215
Experience:  Bachelor of computer science, 5+ years experience in software development, software company owner
Type Your Programming Question Here...
ehabtutor is online now
A new question is answered every 9 seconds

Delete list of file using vb . Net ...I have a automatic ssis

Customer Question

Delete list of file using vb . Net ...I have a automatic ssis backup system, which creates zip file backup every day for multiple database in one folder.I Want a Program which delete any backup older than 2 days. As I am taking backup for multiple database I need to put a check delete old database only if current backup for all database exist other wise throw an exception.

My database name format is .(example)

Database1_fullbackup_201107161345.zip
Database2_fullbackup_201107161346.zip
Database3_fullbackup_201107161345.zip
Database4_fullbackup_201107161346.zip
Database1_ diffbacup_201107161345.zip
Database2_ diffbacup_201107161346.zip

My database name format is .(example)

Database1_fullbackup_201107161345.zip
Database2_fullbackup_201107161346.zip
Database3_fullbackup_ 201107141344.zip
Database4_fullbackup_ 201107141344.zip
Database1_ diffbacup_ 201107141344.zip
Database2_ diffbacup_ 201107141344.zip
Database3_diffbacup_ 201107141344.zip
Database3_diffbacup_ 201107141344.zip
Database4_ diffbacup_201107141344.zip

And so on ..

201107141344 is date and time the file was crated .. I need generic code for this so that it is easy to add and remove database withouch changing the code .. Files can be deleted checking system.file.datemodified or created. I will be using this script in ssis.


Thank you in advance for help.
Submitted: 3 years ago.
Category: Programming
Expert:  ehabtutor replied 3 years ago.

ehabtutor :

hi

ehabtutor :

welcome to just answer

ehabtutor :

it would be my pleasure to help you

ehabtutor :

i have a couple of questions

ehabtutor :

tell me when u are ready

Customer: Hi
ehabtutor :

hi there

ehabtutor :

i need to know do you need this as a windows application that you start and stop

ehabtutor :

or rather a service that runs on windows?

Customer: i actually need a ssis package , just a single vb . Net file to be able to run as a script task in ssis
ehabtutor :

i am not familiar with ssis

ehabtutor :

i can however give you the vb.net file with the function requested

Customer: It's just a platform if you search ssis in google you will know .. I just need a single working vb.net code file
ehabtutor :

ok

ehabtutor :

when do you need this?

ehabtutor :

is tomorow ok?

Customer: I need this in next 10 - 12 hrs
ehabtutor :

i am in a different time zone. so i won't be able to do it before like 20 hours

ehabtutor :

if your time is critical

ehabtutor :

i can opt out and maybe someone can help you earlier

Customer: Will be getting answer in 20 hrs or u will start after 20 hrs ..
ehabtutor :

no you will be getting it in 20 hrs

Customer: Can u make it 15 so that I will have enough time to test
ehabtutor :

i will do my best

ehabtutor :

i want to confirm something

Customer: Ok please ask me if u have any query ,
ehabtutor :

deletion will occur when backup for a current database exists

ehabtutor :

only 2 days older than the current available will be deleted

Customer: Yup! If database1_fullbackup_201107170800.zip exist then delete file two days old for same db. And also every database has different type of backups for example differential backup and full backup .. iAd I mentioned in my question .. File name will indicate type of back up ..
ehabtutor :

so i will also use the file name to identify the backup date right?

ehabtutor :

also by throwing an exception, you mean notify you when only the current db backup is available

ehabtutor :

also what will trigger the deletion? ( a certain event, button ) or you will be handling this

Customer: Yes , but try and make it generic. And exception is when you can not find current database backup file ..
Customer: I will use this as a batch file with windows scheduler ... Please look for ssis script task .. U will find many examples done for deletion of old backup files .. I will be using .dtsx file package .. If u have SQL server management studio it will be easy for u to work
Customer: BDIS , is visual studio extension . You might want to use that for Writting this task
Customer: BIDS
ehabtutor :

yeah i have it

ehabtutor :

ok

ehabtutor :

i meant sql management studio

ehabtutor :

i will look for the BDIS

Customer: so u can open BIDS --- create new project --- from toolbar drag script task-- right click edit scrpt task .. And u are ready to go :)
Customer: Ok
Customer: So let me how how u go
ehabtutor :

ok

ehabtutor :

i will go now and will get back to you

ehabtutor :

have a nice day

Customer: Ok hope to hear from you soon
Customer:

hi

Customer:

any update ?

Expert:  ehabtutor replied 3 years ago.
What Happens Now?

Your chat has ended, but you can still work with your Expert to get an answer to your question if you have not yet received one.

Come back to this page at any time to see additional information from your Expert.  You will also receive an email when your question is updated.  If you want to send a message to your Expert, use the box below.

If you have already received a satisfactory answer to your question, click the Accept button above.  Experts are credited for each accepted answer they provide.
Expert:  ehabtutor replied 3 years ago.
Hi,

Click here to download the file

If you are satisfied with my answer don't forget to hit the accept button so i can get paid for my efforts.

A bonus will be highly appreciated.

If you need a fresh and quick answer, just remember to begin your question with " TO Ehab Tutor Only" and i will be here to help

regards,
ehab tutor
Customer: replied 3 years ago.
Will check ur answer in 1 hr .. Hope to see it working .. Will give u an update soon
Expert:  ehabtutor replied 3 years ago.
ok
Customer: replied 3 years ago.

Hi , Thanks for the code but i need generic code as i mentioned earliar. This is only going to delete file starting with database1 and fullbackup type ..

 

as i mentioned i need something generic for example , it should look for all file and backup for each type and database available then delete old one .

 

hope u can help me

Expert:  ehabtutor replied 3 years ago.

can you give me more time to re develop it

 

regards,

ehab tutor

Customer: replied 3 years ago.

when can u finish it. I think concept is correct just need to be generic .

Expert:  ehabtutor replied 3 years ago.

I can finish it tomorow

 

 

 

regards,

ehab tutor

Customer: replied 3 years ago.
ok , let me know when you are finished
Expert:  ehabtutor replied 3 years ago.

sure i will get back to you

 

regards,

ehab tutor

Customer: replied 3 years ago.
will be waiting
Customer: replied 3 years ago.

' Microsoft SQL Server Integration Services Script Task
' Write scripts using Microsoft Visual Basic
' The ScriptMain class is the entry point of the Script Task.

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.IO
Imports System.Collections

Public Class ScriptMain

' The execution engine calls this method when the task executes.
' To access the object model, use the Dts object. Connections, variables, events,
' and logging features are available as static members of the Dts class.
' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
'
' To open Code and Text Editor Help, press F1.
' To open Object Browser, press Ctrl+Alt+J.

Public Sub Main()
'
' Add your code here
'

Dim di As New DirectoryInfo(Dts.Variables("Dir").Value.ToString())
Dim smFiles As FileInfo() = di.GetFiles("*.zip")

For Each fileName As FileInfo In smFiles
Dim dbNameAndType As String

Dim namePart As String() = fileName.Name.Split(New Char() {"_"c})
dbNameAndType = namePart(0) & "_" & namePart(1) & "_" & namePart(2)
Dim arrDbFiles As New ArrayList()

arrDbFiles = GetAllFiles(dbNameAndType)
' File.Delete(filePath);
DeleteOld(arrDbFiles)

Next

Dts.TaskResult = Dts.Results.Success
End Sub

Private Function GetTimeStamp(ByVal fileName As String) As Int64

Dim arrNamePart As String() = fileName.Split(New Char() {"_"c})
Dim arr As String = arrNamePart(2)

Dim timestamp As String() = arr.Split(New Char() {"."c})

Return Convert.ToInt64(timestamp(0))

End Function
Private Sub DeleteOld(ByVal arrDbFiles As ArrayList)
Dim LatestFile As DateTime
Dim currentFile As DateTime

'GetTimeStamp(arrDbFiles)
Dim cnt As Integer = 0
Dim strLatestFile As String
Dim fileDetails As FileInfo
Dim found As Boolean = False
Dim currentDate As Date = Date.Now
For Each strFile As String In arrDbFiles
Dim dbNameAndType As String

Dim namePart As String() = strFile.Split(New Char() {"_"c})
Dim currentBackupStart As String = namePart(0) & "_" & namePart(1) & "_" & currentDate.ToString("yyyyMMdd")
If strFile.StartsWith(currentBackupStart) Then
found = True
Exit For
End If
'fileDetails = My.Computer.FileSystem.GetFileInfo(strFile)
'currentFile = fileDetails.LastWriteTime()
'If cnt = 0 Then

' currentFile = fileDetails.LastWriteTime()
' LatestFile = currentFile
' strLatestFile = strFile
' cnt += 1
'End If

'If LatestFile > currentFile Then
' LatestFile = currentFile
' strLatestFile = strFile
'End If

Next

'For Each strFile As String In arrDbFiles
' Dim fileDetails As FileInfo
' Dim strLatestFileDetail As FileInfo

' fileDetails = My.Computer.FileSystem.GetFileInfo(strFile)
' strLatestFileDetail = My.Computer.FileSystem.GetFileInfo(strLatestFile)

' If (fileDetails.LastWriteTime() > (DateTime.Now.AddDays(-2))) Then
' 'GetTimeStamp(strFile)
' strLatestFile = strFile
' End If
'Next
If found Then
For Each strFile As String In arrDbFiles
Dim files As FileInfo
files = My.Computer.FileSystem.GetFileInfo(strFile)
If (fileDetails.LastWriteTime() > (DateTime.Now.AddDays(-2))) Then
'If strFile <> strLatestFile Then
File.Delete(Dts.Variables("Dir").Value.ToString() & strFile)
End If

Next
Else
Throw New Exception("Current Backup doesn't exist")
End If

End Sub
Private Function GetDbNameAndType(ByVal fileName As String) As String
Dim namePart As String() = fileName.Split(New Char() {"_"c})

Return namePart(0) & namePart(1)
End Function
Private Function GetAllFiles(ByVal dbNameAndType As String) As ArrayList
Dim arrFiles As New ArrayList()

Dim di As New DirectoryInfo(Dts.Variables("Dir").Value.ToString())
Dim smFiles As FileInfo() = di.GetFiles(dbNameAndType & "_*.zip")


For Each fileName As FileInfo In smFiles
arrFiles.Add(fileName.Name)
Next

Return arrFiles


End Function


End Class

 

 

This is what have been tried but not working properly... might help you to develope

Expert:  ehabtutor replied 3 years ago.

ok

that would be helpful

 

thanks

 

ehab tutor

Expert:  ehabtutor replied 3 years ago.
Here you are the modified version
http://www.mediafire.com/?ruvlwcznqprxdvl

please replace "directory" with "dts"


Don't forget to hit the accept button if you are satisfied with my help
A bonus and a positive feedback will be highly appreciated.

If you need my help anytime. just start your question with " To Ehab Tutor Only"

regards,
ehab tutor
ehabtutor, Computer Software Engineer
Category: Programming
Satisfied Customers: 1215
Experience: Bachelor of computer science, 5+ years experience in software development, software company owner
ehabtutor and 2 other Programming Specialists are ready to help you
Customer: replied 2 years ago.
Hi there ! you helped me on above question couple of months ago and every thing was working fine. By accident I have lost that project file and I have to re-work on this question by any chance do you have that file with you. I am ready to put this as new question so that you can get paid .

Please help.
Expert:  ehabtutor replied 2 years ago.

hi,

 

i will search for it.

 

if you are going to put as a new question, start it with " To Ehab Tutor Only"

 

 

thanks

 

regards,

ehab tutor

JustAnswer in the News:

 
 
 
Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.
 
 
 

What Customers are Saying:

 
 
 
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer New York
< Last | Next >
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer New York
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex Los Angeles, CA
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP Hesperia, CA
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin Kernersville, NC
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther Woodstock, NY
  • Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know. Robin Elkton, Maryland
 
 
 

Meet The Experts:

 
 
 
  • ATLPROG

    Computer Software Engineer

    Satisfied Customers:

    7463
    MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
< Last | Next >
  • http://ww2.justanswer.com/uploads/SP/spatlanta2010/2011-6-23_12450_photo.64x64.gif ATLPROG's Avatar

    ATLPROG

    Computer Software Engineer

    Satisfied Customers:

    7463
    MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
  • http://ww2.justanswer.com/uploads/ComputersGuru/2010-02-13_051118_Photo41.JPG LogicPro's Avatar

    LogicPro

    Computer Software Engineer

    Satisfied Customers:

    5603
    Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.
  • http://ww2.justanswer.com/uploads/unvadim/2010-11-15_210218_avatar.jpg unvadim's Avatar

    unvadim

    Computer Software Engineer

    Satisfied Customers:

    1158
    Good knowledge of OOP principles. 3+ years of programming experience with Java and C++. Sun Certified Java Programmer 5.0.
  • http://ww2.justanswer.com/uploads/lifesaver333/2010-10-17_191349_ls.jpeg lifesaver's Avatar

    lifesaver

    Computer Software Engineer

    Satisfied Customers:

    950
    Several years of intensive programming and application development experience in various platforms.
  • http://ww2.justanswer.com/uploads/EH/ehabtutor/2012-8-2_202016_1.64x64.jpg ehabtutor's Avatar

    ehabtutor

    Computer Software Engineer

    Satisfied Customers:

    864
    Bachelor of computer science, 5+ years experience in software development, software company owner
  • http://ww2.justanswer.com/uploads/RA/rajivsharma086/2012-6-6_17128_displaypic.64x64.jpg Raj's Avatar

    Raj

    Computer Engg.

    Satisfied Customers:

    860
    BE CS, 4+ Experience in Programming and Database (ERP)
  • http://ww2.justanswer.com/uploads/eljonis/2010-01-06_130406_eljon2.jpg Eljon's Avatar

    Eljon

    Consultant

    Satisfied Customers:

    590
    11 yrs of programming (PHP, WordPress, XSL, SQL, JavaScript)