Deleting a Remote file placed in same network through VBScript-ASP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vyas111111
    New Member
    • Sep 2007
    • 13

    Deleting a Remote file placed in same network through VBScript-ASP

    Hello all
    I want to delete a file which is not placed on my local machine, it is placed on diffrent machine but in the same network. How can i delete that file , i am using VBScript -ASP
    Thanks in advanced
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    Use Filesystemobjec t to deal with the files.
    e.g.
    Code:
          <%
    
                         Dim fso
                         Dim filename
                         set fso = Server.CreateObject("Scripting.FileSystemObject")
    
                         ''''Path of the file to be deleted
                         filename = "\example.txt"   
                         
                         '''Check if file exists before deleting
    
                         If fso.FileExists(filename) then
                              ''''Delete the file
                              fso.DeleteFile(filename)
                        else
                             Response.write("File does not exists")
                        end if 
                        set fso = nothing
           %>
    Originally posted by Vyas111111
    Hello all
    I want to delete a file which is not placed on my local machine, it is placed on diffrent machine but in the same network. How can i delete that file , i am using VBScript -ASP
    Thanks in advanced

    Comment

    • Vyas111111
      New Member
      • Sep 2007
      • 13

      #3
      Hi Shweta
      Thanks For The quick Reply,i have tried your code it will run fine if my file is on the local system,but I have to delete a file which is placed on some other system but both system are in same network.
      Originally posted by shweta123
      Hi,

      Use Filesystemobjec t to deal with the files.
      e.g.
      Code:
            <%
      
                           Dim fso
                           Dim filename
                           set fso = Server.CreateObject("Scripting.FileSystemObject")
      
                           ''''Path of the file to be deleted
                           filename = "\example.txt"   
                           
                           '''Check if file exists before deleting
      
                           If fso.FileExists(filename) then
                                ''''Delete the file
                                fso.DeleteFile(filename)
                          else
                               Response.write("File does not exists")
                          end if 
                          set fso = nothing
             %>

      Comment

      • shweta123
        Recognized Expert Contributor
        • Nov 2006
        • 692

        #4
        Hi,

        If the file is located on the remote machine then give the full path of the filename.

        e.g.

        If the file is located on the remote machine with the name "remote-machine"
        then full path will be //remote-machine/filename or if you dont know the machine name on the remote system you can also use IP address of the machine you want to access.


        Originally posted by Vyas111111
        Hi Shweta
        Thanks For The quick Reply,i have tried your code it will run fine if my file is on the local system,but I have to delete a file which is placed on some other system but both system are in same network.

        Comment

        • Vyas111111
          New Member
          • Sep 2007
          • 13

          #5
          I have tried with IP Address as well as Machine name but error comes like netwrok path not found,infact network path is correct. I have tried it as follow

          Code:
          Dim objFSO,filename
          Set objFSO = CreateObject("Scripting.FileSystemObject")
          objFSO.DeleteFile "\\\\192.168.2.241\\c:\\test.txt",true
          But i got error like Network Path was not found same in the case of Machine name

          Originally posted by shweta123
          Hi,

          If the file is located on the remote machine then give the full path of the filename.

          e.g.

          If the file is located on the remote machine with the name "remote-machine"
          then full path will be //remote-machine/filename or if you dont know the machine name on the remote system you can also use IP address of the machine you want to access.
          Last edited by Vyas111111; Nov 16 '07, 06:21 AM. Reason: Some Code has been updated

          Comment

          • shweta123
            Recognized Expert Contributor
            • Nov 2006
            • 692

            #6
            Hi,

            Try to give path like this :

            objFSO.DeleteFi le "\\192.168.2.24 1\test.txt",tru e
            OR
            objFSO.DeleteFi le "\\machinename\ test.txt",true




            Originally posted by Vyas111111
            I have tried with IP Address as well as Machine name but error comes like netwrok path not found,infact network path is correct. I have tried it as follow

            Code:
            Dim objFSO,filename
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            objFSO.DeleteFile "\\\\192.168.2.241\\c:\\test.txt",true
            But i got error like Network Path was not found same in the case of Machine name

            Comment

            • Vyas111111
              New Member
              • Sep 2007
              • 13

              #7
              Hi have already tried like you told but i got error "File Not Found"
              Please help me out from this

              Originally posted by shweta123
              Hi,

              Try to give path like this :

              objFSO.DeleteFi le "\\192.168.2.24 1\test.txt",tru e
              OR
              objFSO.DeleteFi le "\\machinename\ test.txt",true

              Comment

              • jhardman
                Recognized Expert Specialist
                • Jan 2007
                • 3405

                #8
                someone recently told me you have to use wscript.shell (I'm not sure if I spelled that right) to do that, but I have never tried. I think it works similar to scripting.fileS ystemObject

                Jared

                Comment

                • Vyas111111
                  New Member
                  • Sep 2007
                  • 13

                  #9
                  Hi shweta,
                  Thanks a lot your code working fine now,Previously i forgot to enable "full control" attribute of that file without which we cant delete remote file.
                  Thanks a lot.
                  Bye Take care
                  Originally posted by shweta123
                  Hi,

                  Try to give path like this :

                  objFSO.DeleteFi le "\\192.168.2.24 1\test.txt",tru e
                  OR
                  objFSO.DeleteFi le "\\machinename\ test.txt",true

                  Comment

                  • mastanrao
                    New Member
                    • Jan 2008
                    • 10

                    #10
                    Originally posted by shweta123
                    Hi,

                    Use Filesystemobjec t to deal with the files.
                    e.g.
                    Code:
                          <%
                    
                                         Dim fso
                                         Dim filename
                                         set fso = Server.CreateObject("Scripting.FileSystemObject")
                    
                                         ''''Path of the file to be deleted
                                         filename = "\example.txt"   
                                         
                                         '''Check if file exists before deleting
                    
                                         If fso.FileExists(filename) then
                                              ''''Delete the file
                                              fso.DeleteFile(filename)
                                        else
                                             Response.write("File does not exists")
                                        end if 
                                        set fso = nothing
                           %>
                    Hi,
                    I need open the file in different system.How can i open that file in my system.There systems are all in local network.Please send me the solution asap.it is developing the applications in .net
                    Thanks a lot.

                    Comment

                    Working...