Results 1 to 12 of 12

Thread: filesystemobject

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2008
    Posts
    17

    filesystemobject

    In the following code

    private sub main()
    dim a as new filesystemobject
    set corp=a.copyfile("c:\test.txt","c:\aim")
    set corp=nothing
    set a=nothing
    end sub


    microsoft scripting run time is checked in project refrences.

    but i get a error
    "compile error: expected function or variable:

    plz advise

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: filesystemobject

    Get rid of all that code and use this:
    vb.net Code:
    1. My.Computer.FileSystem.CopyFile("c:\test.txt","c:\aim\test.txt")
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2008
    Posts
    17

    Re: filesystemobject

    i have to code in visual basic 6.0 and not in vb.net

  4. #4
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    Re: filesystemobject

    then this is not the right section to post those kind of threads.
    C# and WPF developer
    My Website:
    http://singlebits.com/

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: filesystemobject

    Quote Originally Posted by pradeep_pvnm
    i have to code in visual basic 6.0 and not in vb.net
    Yeah, reading the names and descriptions of the forums on the front page before posting is always a good idea. I've asked the mods to move this thread to the proper forum.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: filesystemobject

    Thread moved from 'VB.Net' (VB2002 and later) forum to 'VB6 and Earlier' forum


    Quote Originally Posted by jmcilhinney
    I've asked the mods to move this thread to the proper forum.
    Thanks, as always.

  7. #7
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: filesystemobject

    CopyFiile is a Sub, not a function. Os it doesnt return anything. SO you cant assign the return value to corp (its not declared too).
    Try Like This

    Code:
    Dim a As New FileSystemObject
        a.CopyFile "c:\test.txt", "c:\aim"
        Set a = Nothing
    IIF(Post.Rate > 0 , , )

  8. #8

    Thread Starter
    Junior Member
    Join Date
    May 2008
    Posts
    17

    Re: filesystemobject

    Thanks a lot for the replies and apoligies for posting in the wrong forum

    by the way i found out the error myself

    the error was in the path, the destination has to be c:\aim\ and not c:\aim

    thanks again!!!

  9. #9

    Thread Starter
    Junior Member
    Join Date
    May 2008
    Posts
    17

    Re: filesystemobject

    now a new doubt!

    Dim a As New FileSystemObject
    a.movefile "c:\aim\test.txt", "c:\aim\test1.txt"
    Set a = Nothing
    when i am trying to rename the file
    i get permission denied error.

    first i thought it has to do something with write permissions on the folder.
    but i am manually able to edit the files and delete the files in the folder.
    moreover i am able to write to a file using vb also but not able to rename or delete it

    let me know your thoughts

  10. #10
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: filesystemobject

    I don't think FSO can move an in-use file. Could that be it?

  11. #11
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: filesystemobject

    Is there a particular reason you are using fso? I think the native VB6 functions might be less of a hassle:
    vb Code:
    1. FileCopy "c:\test.txt", "c:\aim\test.txt"
    2. Name "c:\aim\test.txt" As "c:\aim\New.txt"
    FileCopy can rename the file as it copies, and Name can move the file to a new folder instead of just renaming it.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    May 2008
    Posts
    17

    Re: filesystemobject

    Thanks a ton ppl
    the reason for the error was that the file was open and the filesystem object cannot delete a file in use
    hence i included a .close satatement and it worked!!!

    Thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width