|
-
May 31st, 2008, 12:10 PM
#1
Thread Starter
Junior Member
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
-
May 31st, 2008, 11:53 PM
#2
Re: filesystemobject
Get rid of all that code and use this:
vb.net Code:
My.Computer.FileSystem.CopyFile("c:\test.txt","c:\aim\test.txt")
-
Jun 1st, 2008, 12:44 AM
#3
Thread Starter
Junior Member
Re: filesystemobject
i have to code in visual basic 6.0 and not in vb.net
-
Jun 1st, 2008, 12:47 AM
#4
Hyperactive Member
Re: filesystemobject
then this is not the right section to post those kind of threads.
-
Jun 1st, 2008, 07:06 AM
#5
Re: filesystemobject
 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.
-
Jun 1st, 2008, 07:07 AM
#6
Re: filesystemobject
Thread moved from 'VB.Net' (VB2002 and later) forum to 'VB6 and Earlier' forum
 Originally Posted by jmcilhinney
I've asked the mods to move this thread to the proper forum.
Thanks, as always.
-
Jun 1st, 2008, 07:19 AM
#7
Frenzied Member
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
-
Jun 2nd, 2008, 10:46 AM
#8
Thread Starter
Junior Member
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!!!
-
Jun 2nd, 2008, 10:51 AM
#9
Thread Starter
Junior Member
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
-
Jun 2nd, 2008, 05:56 PM
#10
Re: filesystemobject
I don't think FSO can move an in-use file. Could that be it?
-
Jun 2nd, 2008, 06:57 PM
#11
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:
FileCopy "c:\test.txt", "c:\aim\test.txt"
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.
-
Jun 3rd, 2008, 10:13 AM
#12
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|