473,467 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Create 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("Directory " & path & " Found!")
File.Copy(strSender, path & strTargetFile) ' Now copy
the file
End If
Catch
Console.WriteLine("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 3241
Try adding a "\"
after path if its not there allready.

Just a stab in the dark.

Michael.
"Saabster" <cb******@sbcglobal.netwrote in message
news:11**********************@38g2000cwa.googlegro ups.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("Directory " & path & " Found!")
File.Copy(strSender, path & strTargetFile) ' Now copy
the file
End If
Catch
Console.WriteLine("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:\Destination\One.xls"

it will do

File.Copy("One.xls","C:\DestinationOne.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("Name of your file") and
Directory.Exisits("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(strSender, path & strTargetFile) ' Now copy
Instead of

File.Copy(strSender, path & strTargetFile)

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

File.Copy(strSender, 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("Directory " & path & " Found!")
File.Copy(strSender, path & strTargetFile) ' Now copy
the file
End If
Catch
Console.WriteLine("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
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 --...
2
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...
5
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...
1
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...
2
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...
11
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...
2
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...
6
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...
8
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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 ...

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.