473,786 Members | 2,608 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why is this file.copy not working

Hi all,

It's always the simple stuff that trips you up I guess. Here is the
issue I'm dealing with.

I have a folder with 1400 excel files that I need to move to another
location. Since each file has to go in to a particular target folder I
decided that writing a program to move the files is they way to go.

I've got all but this last piece down. and for the life of me I can't
understand why the file.copy statement will not copy the file.

Try
If InStr(path, strTargetPath) Then 'We Found the Correct
Target Folder
MsgBox("Directo ry " & path & " Found!")
File.Copy(strSe nder, path & strTargetFile) ' Now copy
the file
End If
Catch
Console.WriteLi ne("Error.")
End Try

The copy appears to work when I step through the code, but when I check
the target folder the copied file is not there.

Can anyone tell me why this is happening (or not as the case is)? I
have verified that the source file exists, as well as the target folder
and there is no file with the same name in the target.

Please help. this is the last piece of the puzzle.

Thanks

Craig

Jan 6 '07 #1
5 3264
Try adding a "\"
after path if its not there allready.

Just a stab in the dark.

Michael.
"Saabster" <cb******@sbcgl obal.netwrote in message
news:11******** **************@ 38g2000cwa.goog legroups.com...
Hi all,

It's always the simple stuff that trips you up I guess. Here is the
issue I'm dealing with.

I have a folder with 1400 excel files that I need to move to another
location. Since each file has to go in to a particular target folder I
decided that writing a program to move the files is they way to go.

I've got all but this last piece down. and for the life of me I can't
understand why the file.copy statement will not copy the file.

Try
If InStr(path, strTargetPath) Then 'We Found the Correct
Target Folder
MsgBox("Directo ry " & path & " Found!")
File.Copy(strSe nder, path & strTargetFile) ' Now copy
the file
End If
Catch
Console.WriteLi ne("Error.")
End Try

The copy appears to work when I step through the code, but when I check
the target folder the copied file is not there.

Can anyone tell me why this is happening (or not as the case is)? I
have verified that the source file exists, as well as the target folder
and there is no file with the same name in the target.

Please help. this is the last piece of the puzzle.

Thanks

Craig

Jan 6 '07 #2
On Sat, 6 Jan 2007 02:15:52 -0000, Michael M. wrote:
Try adding a "\"
after path if its not there allready.

Just a stab in the dark.

Michael.

Like Michaels says, you might need to add a '\' after the path or instead
of doing

File.Copy("One. xls","C:\Destin ation\One.xls"

it will do

File.Copy("One. xls","C:\Destin ationOne.xls"

in which case the file will be copied and end up in the parent folder from
where you inteded it to go.

Also you might want to use File.Exists("Na me of your file") and
Directory.Exisi ts("Name of your directory") to check for the existence of
files and directories rather than instr

--
Bits.Bytes
http://bytes.thinkersroom.com
Jan 6 '07 #3
Saabster wrote:
File.Copy(strSe nder, path & strTargetFile) ' Now copy
Instead of

File.Copy(strSe nder, path & strTargetFile)

which is vulnerable to missing (or multiple) '\'s, try

File.Copy(strSe nder, Path.Combine( path, strTargetFile ) )

which takes care of this for you.

HTH,
Phill W.
Jan 8 '07 #4
Hi:

Newbie here. Was in the middle of doing a
series of forms with labels and buttons and,
all of a sudden, I could no longer stretch
any objects on some forms. I did not
consciously do anything to cause this. Did I
accidentally type a keystroke to lock
everything? Right click and "lock" is not on
anything. I have closed the file and
program, reopened it and the like. Looked at
the MSDN site, etc. I have looked at all
property sheets from those of the object, the
form and the application.

Any ideas?

Also, in VB 6 there was an "MDI Child" yes/no
on all forms..... I made an MDI form, but how
do I add forms to it?

Thanks So Much,

BZ
Jan 8 '07 #5
Thanks All, it was the missing "\" that was the problem. Phil, I like
your solution. Consider it implemented.

Craig
Saabster wrote:
Hi all,

It's always the simple stuff that trips you up I guess. Here is the
issue I'm dealing with.

I have a folder with 1400 excel files that I need to move to another
location. Since each file has to go in to a particular target folder I
decided that writing a program to move the files is they way to go.

I've got all but this last piece down. and for the life of me I can't
understand why the file.copy statement will not copy the file.

Try
If InStr(path, strTargetPath) Then 'We Found the Correct
Target Folder
MsgBox("Directo ry " & path & " Found!")
File.Copy(strSe nder, path & strTargetFile) ' Now copy
the file
End If
Catch
Console.WriteLi ne("Error.")
End Try

The copy appears to work when I step through the code, but when I check
the target folder the copied file is not there.

Can anyone tell me why this is happening (or not as the case is)? I
have verified that the source file exists, as well as the target folder
and there is no file with the same name in the target.

Please help. this is the last piece of the puzzle.

Thanks

Craig
Jan 8 '07 #6

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

Similar topics

3
2888
by: Philipp Lenssen | last post by:
I have this XML file which I would like to XSLT-sort based on the string contained within the item-children elements using basic MSXML (no recent version of IIS, so it might be an outdated MSXML -- pretty sure not MSXML4, though tips on how to do it with that are appreciated too): ----------- Translation Dictionary (German) ---- <?xml version="1.0" encoding="iso-8859-1"?> <items> <item id="4">
2
1830
by: bmcelhany | last post by:
Hi all, I have a solution with 4 projects: a class library, a windows app, a windows service, and an installer project. The class library handles all communication with the database and its classes are used by both the application and the service. I have stored the database connection string in an app.config file located in the class library project. Everything was working fine on my dev box, but when I migrated to the QA box, I...
5
1782
by: Henry Jordon | last post by:
hello I was wondering if someone could help me get a main going on this project I've completed the header file that the professor started us on but not really sure how to get the main going. If someone could please give me some pointers it would greatly be appreciated. Again thanks for the help. Henry headerfile:
1
1977
by: LenS | last post by:
If this is the wrong place to post this, please advise better place. Otherwise, I have created the following python program and it works. Running on XP. I think I am now at that stage of learning python where I'm not quit a newbie and I am not really knowlegable. I know just enough to be dangerous and can really screw things up. Any suggestion on improving would be greatly appreciated. However my real question is I would like to run...
2
5830
by: Ram | last post by:
Hey, I have a solution that is built from both C# and VB.Net projects that some C# projects are referenced to VB.Net projects and vise versa. Whenever I try to rebuild my solution I get the following errors: "Cannot Copy Assembly <Assembly> - The Process Cannot Access The File Because It Is Being Used By Another Process". I tried to "kill" the ASPNET_WP process in a pre-built event and had no success... I read in more than a few old...
11
5580
by: Tark Siala | last post by:
hi i'm working on VB.NET 203 and i'm working on application that read Metadata from Photo Take it from Digital Camera. i'm use this code: Dim imageX = New Bitmap(PhotoFullFileNameX) Dim propItems As PropertyItem() = imageX.PropertyItems
2
4029
by: johnny | last post by:
hi all, I wonder why this little script doesn't work, maybe it's the provider not allowing the use of load data infile ( I know some don't let users to run some tasks ), could you please tell me if the script it's right before I ask the provider ? I can insert data into the table using fgetcsv as well with no problems,but I would like to understand. TIA
6
1711
by: naima.mans | last post by:
Hello :) I'm newbie to XSLT and i need some advice please: Here the action: I have to browse an XML file with xslt : For each node i have to determinate if it is a node where i need to add an attribute... The question is:
8
3880
by: The Natural Philosopher | last post by:
This is so weird. What I am trying to do is to upload files and stuff them in a mysql database. Everything works except the file content is zero. using the load_file command from mysql command line as 'root' works and i can download the inserted file ok.
0
9650
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
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,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9962
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...
1
7515
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
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.