help in filesystem object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muddasirmunir
    Contributor
    • Jan 2007
    • 284

    #1

    help in filesystem object

    i want to copy a specific file and paste into another folder
    i am using the following code

    Code:
     '' getting the required file to be copied 
    fso.GetFile "D:\Data\smeb_Data.MDF"
     
    '' creating newfolder 
    If fso.FolderExists("H:\Backup") Then
    Else
    fso.CreateFolder "H:\Backup"
    End If
     
    ''pasting the file
    fso.CopyFile "H:\Backup\smeb_Data.MDF"
    Exit Sub

    when i run this code i get errror
    "argument not optional "

    what chages i have to made in it
    any help

    i also want to copy more than one files and it should be pasted with
    out promting that file already exists
  • jg007
    Contributor
    • Mar 2008
    • 283

    #2
    Originally posted by muddasirmunir
    i want to copy a specific file and paste into another folder
    my VB is a bid lousy but this worked for me -

    Code:
     
    
          '' getting the required file to be copied 
    
            Dim fso As System.IO.FileInfo = FileIO.FileSystem.GetFileInfo("D:\Data\smeb_Data.MDF")
    
    
            ' creating newfolder 
            If FileIO.FileSystem.DirectoryExists("H:\Backup") Then
            Else
                FileIO.FileSystem.CreateDirectory("H:\Backup")
    
            End If
    
            ''pasting the file
            fso.CopyTo("H:\Backup\" & fso.Name)
    Last edited by jg007; Mar 23 '08, 10:47 AM. Reason: left too much of quote in

    Comment

    • muddasirmunir
      Contributor
      • Jan 2007
      • 284

      #3
      there is something wrong in line

      Code:
       
      Dim fso As System.IO.FileInfo = FileIO.FileSystem.GetFileInfo("D:\Data\smeb_Data.MDF")
      vb is showing it as red colour and giving error
      "expected end of statement"





      Originally posted by jg007
      my VB is a bid lousy but this worked for me -

      Code:
       
       
      '' getting the required file to be copied 
       
      Dim fso As System.IO.FileInfo = FileIO.FileSystem.GetFileInfo("D:\Data\smeb_Data.MDF")
       
       
      ' creating newfolder 
      If FileIO.FileSystem.DirectoryExists("H:\Backup") Then
      Else
      FileIO.FileSystem.CreateDirectory("H:\Backup")
       
      End If
       
      ''pasting the file
      fso.CopyTo("H:\Backup\" & fso.Name)

      Comment

      • jg007
        Contributor
        • Mar 2008
        • 283

        #4
        are you entering it all as one line?, also it is VB.net and I noticed later that you are using VB 6

        Comment

        • lotus18
          Contributor
          • Nov 2007
          • 865

          #5
          Try:
          [CODE=vb]
          Dim fso As New FileSystemObjec t
          Dim s As String

          s="D:\Data\smeb _Data.MDF"

          If fso.FolderExist s("H:\Backup")= False Then
          fso.CreateFolde r "H:\Backup"
          End If

          fso.CopyFile s, "H:\Backup\smeb _Data.MDF"
          Exit Sub

          [/CODE]

          Line 10, argument is not optional because you didn't specify the path to paste the file.

          Rey Sean

          Comment

          • muddasirmunir
            Contributor
            • Jan 2007
            • 284

            #6
            thanks this code works



            Originally posted by lotus18
            Try:
            [CODE=vb]
            Dim fso As New FileSystemObjec t
            Dim s As String

            s="D:\Data\smeb _Data.MDF"

            If fso.FolderExist s("H:\Backup")= False Then
            fso.CreateFolde r "H:\Backup"
            End If

            fso.CopyFile s, "H:\Backup\smeb _Data.MDF"
            Exit Sub

            [/CODE]

            Line 11, argument is not optional because you didn't specify the path to paste the file.

            Rey Sean

            Comment

            • lotus18
              Contributor
              • Nov 2007
              • 865

              #7
              Glad we could help : )

              Rey Sean

              Comment

              Working...