473,785 Members | 2,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Syntax for copying a file from one folder to another?

I am trying to write a simple on click procedure to copy a file who's name
is in a combo box on the form to another folder and overwrite the file by
the same name which is already there.

I have the following, but the CopyFile part does not work. It goes straight
through to the last message box and no file is copied.
Dim fso
Dim sfol As String, dfol As String
sfol = (CurrentProject .Path & "\TemplatesBack up")
dfol = CurrentProject. Path & "\Templates "
Set fso = CreateObject("S cripting.FileSy stemObject")
On Error Resume Next
If Not fso.folderexist s(sfol) Then
MsgBox sfol & " is not a valid folder/path.", vbInformation, "Invalid
Source"
ElseIf Not fso.folderexist s(dfol) Then
MsgBox dfol & " is not a valid folder/path.", vbInformation, "Invalid
Destination"
Else
fso.CopyFile sfol & "\" & (Me![cboLetterName]) & ".dot", dfol & "\",
True
MsgBox "Your original selected template has been overwritten.",
vbInformation, "Success"

End If
If Err.Number = 53 Then
Exit Sub
End If
\
can anyone help me make this work, I have spent half the afternoon trying
brackets and quotes and all manner of small changes, but to no avail.

TIA
dixie
Mar 2 '07 #1
5 2652
Dixie wrote:
I am trying to write a simple on click procedure to copy a file who's name
is in a combo box on the form to another folder and overwrite the file by
the same name which is already there.

I have the following, but the CopyFile part does not work. It goes straight
through to the last message box and no file is copied.
Dim fso
Dim sfol As String, dfol As String
sfol = (CurrentProject .Path & "\TemplatesBack up")
dfol = CurrentProject. Path & "\Templates "
Set fso = CreateObject("S cripting.FileSy stemObject")
On Error Resume Next
If Not fso.folderexist s(sfol) Then
MsgBox sfol & " is not a valid folder/path.", vbInformation, "Invalid
Source"
ElseIf Not fso.folderexist s(dfol) Then
MsgBox dfol & " is not a valid folder/path.", vbInformation, "Invalid
Destination"
Else
fso.CopyFile sfol & "\" & (Me![cboLetterName]) & ".dot", dfol & "\",
True
MsgBox "Your original selected template has been overwritten.",
vbInformation, "Success"

End If
If Err.Number = 53 Then
Exit Sub
End If
\
can anyone help me make this work, I have spent half the afternoon trying
brackets and quotes and all manner of small changes, but to no avail.

TIA
dixie

Look at the FileCopy Statement in help.
Mar 2 '07 #2
Probably forgot to wrap funny paths with double-quotes.
salad is right: why do this the hard way with FSO?
-Tom.

Mar 2 '07 #3
It's OK anyway, guys, thanks for pointing that out. My main problem was
that the file I was trying to replace was read-only and I had to add some
code to change it to vbNormal before I could overwrite it.

dixie

"Tom van Stiphout" <no************ *@cox.netwrote in message
news:pb******** *************** *********@4ax.c om...
Probably forgot to wrap funny paths with double-quotes.
salad is right: why do this the hard way with FSO?
-Tom.

Mar 5 '07 #4
"Dixie" <di***@dogmail. comwrote in
news:12******** *****@corp.supe rnews.com:
It's OK anyway, guys, thanks for pointing that out. My main problem
was that the file I was trying to replace was read-only and I had to
add some code to change it to vbNormal before I could overwrite it.

dixie
vbNormal will work on your computer?
Mar 5 '07 #5
Shouldn't it? AFAIK it does. I'll check later when I get home.

dixie

"lyle fairfield" <ly******@yahoo .cawrote in message
news:u0******** *****@read2.cgo cable.net...
"Dixie" <di***@dogmail. comwrote in
news:12******** *****@corp.supe rnews.com:
>It's OK anyway, guys, thanks for pointing that out. My main problem
was that the file I was trying to replace was read-only and I had to
add some code to change it to vbNormal before I could overwrite it.

dixie

vbNormal will work on your computer?

Mar 7 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3035
by: Raghul | last post by:
hi I am having a problem. I want to copy a file from the folder and paste it or move it to another folder. Is it possible in python? Actually I need to implement this in the zope for my site. When I click any file it should move or copied to another folder in the same machine using zope. Thanks in advance.
8
17039
by: Ram Baruch | last post by:
Hi, I'm trying to use the File.Copy() function. It works well when the desenation file is local (Like: C:\dest\dest.exe). The problem is that when I'm trying to copy to a destenation that starts with '\\' it doesnt work and exception is thrown (for example: \\MyComputer\DestDirectory). Even if the first and the second directories are actually the same- the File.Copy() doesn't work. Is there any way to copy a file to a different computer?...
5
2355
by: TB | last post by:
Hi All: This news group is proving to be great help on my path towards mastering ASP.NET thanks to all of you helpful souls out there. I am looking forward to the day when I can contribute with a few ounces of hard-won knowledge as well. Meanwhile I have this (hopefully small) problem.
10
7838
by: Martin Ho | last post by:
I am running into one really big problem. I wrote a script in vb.net to make a copy of folders and subfolder to another destination: - in 'from.txt' I specify which folders to copy - in 'to.txt' I specify where to copy it - After I read content of 'to.txt' I create one more subfolder named by current date and thats where everything gets to be copied
4
1406
by: tshad | last post by:
I have an old version of VS 2002 and want to make a copy of my Visual Studio project to another project with another name. In VS 2003, you can do it but there is no copy project command in VS 2002 (at least I can't seem to find it). Is there a way to do it? Thanks, Tom
17
2922
by: Michael | last post by:
Hello, I am writing an app that will sit on the desktop. It needs to be able to make a copy of a folder that sits on the server. It will copy the folder from the server and place it in the same directory on the same server. This is the line of code that I am using: System.IO.File.Copy(sDistinationFolder + "NewOrderTemplate", sDistinationFolder + myDate.Date + "_" + mtxtJobNumber.Text); So, as you can see, I am copying a folder...
5
3578
by: wassimdaccache | last post by:
Hyyy I do have a database that I saved on c:\wasspro\mydb in the folder wasspro I have another folder called image . what i need is to copy folder wasspro into another directory d:\backup I tried to make a file using the notepad and I saved the file as test.bat c:
0
1252
by: redAllison21 | last post by:
what i have is a folder that has over 1000 pdf's inside it. I also have a program that runs a querey in SAP and returns a text file with certain pdfs that need to be copied into another folder to be shipped out to the field. currently i have my secretary that moves these files manually. I have began to create a program that will read the text file then copy these automaticly. I have been able to make a button and textbox that will create the...
13
10727
by: writeson | last post by:
Hi all, I'm writing some code that monitors a directory for the appearance of files from a workflow. When those files appear I write a command file to a device that tells the device how to process the file. The appearance of the command file triggers the device to grab the original file. My problem is I don't want to write the command file to the device until the original file from the workflow has been copied completely. Since these...
0
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.