Delete files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nagmvs
    New Member
    • Aug 2008
    • 49

    Delete files

    Can somebody help me out with a code snippet to cut files from one folder to another in vb.. i.e cut all from src to dest and delete it from src ..


    Thanks,
    Nag.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    you need to use FILESYSTEMOBJEC T for this .

    Comment

    • lee123
      Contributor
      • Feb 2007
      • 556

      #3
      here is a ay to do this i have been working on this and it works. remeber when using the "FILESYSTEMOBJE CT" you have to use the "Microsoft Scripting Runtime" in the in "Project: under Reference"

      and way try this:
      Code:
      Private Sub cmdDelete_Click()
      Dim response As String
      Dim fso As New FileSystemObject, fldr As Folder, s As String
      If cmdDelete Then
          response = MsgBox("Are You Sure you want To Delete This Folder, The Content of the Files In It Will Be Deleted As Well?", vbYesNo + vbQuestion, "Response")
          fso.DeleteFolder (the name of folder goes here), True
          MsgBox "Folder Has Been Deleted!", , "Deleted Folder is Complete"
          txtDeleteFolder.Text = ""
      End If
      End Sub
      in this code i used a Textbox to enter in a folder i wanted to delete, then i asked a question if they wanted to delete this folder. but you can try other things out.

      lee123

      Comment

      • nagmvs
        New Member
        • Aug 2008
        • 49

        #4
        Originally posted by lee123
        here is a ay to do this i have been working on this and it works. remeber when using the "FILESYSTEMOBJE CT" you have to use the "Microsoft Scripting Runtime" in the in "Project: under Reference"

        and way try this:
        Code:
        Private Sub cmdDelete_Click()
        Dim response As String
        Dim fso As New FileSystemObject, fldr As Folder, s As String
        If cmdDelete Then
            response = MsgBox("Are You Sure you want To Delete This Folder, The Content of the Files In It Will Be Deleted As Well?", vbYesNo + vbQuestion, "Response")
            fso.DeleteFolder (the name of folder goes here), True
            MsgBox "Folder Has Been Deleted!", , "Deleted Folder is Complete"
            txtDeleteFolder.Text = ""
        End If
        End Sub
        in this code i used a Textbox to enter in a folder i wanted to delete, then i asked a question if they wanted to delete this folder. but you can try other things out.

        lee123


        Hello lee,

        Ur code is 100% working,Great.T hanks for sending me this code.Sir actually i don't want to delete total folder i want to delete the files on that folder only.So how can i achieve that.i try some methods using ur code but i am not successfull.So please help me to delete the files on that folder only.
        Otherwise i just copy or cut the files on that folder and move those files to some other system.(is it possible ?) how can i do this ? any ideas ?
        Sir i have one doubt.after compiling ur code in vb,the specified folder is deleted successfully. but i can't see that folder in Recycle Bin.so where is it going in my system.In my system which place i can find that deleted folder.

        Thanks,
        Nagesh.

        Comment

        • nagmvs
          New Member
          • Aug 2008
          • 49

          #5
          Originally posted by debasisdas
          you need to use FILESYSTEMOBJEC T for this .

          Oh that's fne.thanks.

          Comment

          • debasisdas
            Recognized Expert Expert
            • Dec 2006
            • 8119

            #6
            try to use this

            [code=vb]
            Set fso = Server.CreateOb ject("Scripting .FileSystemObje ct")
            Set fileObject = fso.GetFile(sou rce filename)
            response.Write( targetfilename)
            fso.moveFile sourcefilename, TargetFileName
            [/code]

            you need to use

            FSO.FileExists( File)
            to check if the file exists before moving the file.
            better to use common dialog control to select the file

            Comment

            Working...