Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Filecopy

Posted on 2004-03-29
22
Medium Priority
?
2,344 Views
Last Modified: 2010-08-05
Hi everyone
I use vb6 and the filecopy statement to copy a zipped mdb file over isdn routers.
Are there any faster filecopy functions available in vb6 , I know there are possibilities to copy faster when I have windows programs that copy the same file in half the time. Is it also possible to get a event triggered to se how much of the file has been copied so I can make a progressbar for that spesifict file??

0
Comment
Question by:haggmar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 9
22 Comments
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 10702413
if u wanna use ur own progress bar u must copy ur file with codes... block by block

u can use Ftp upload or u can use Internet functions to get or put files to other Computers...

o can read file in to a stream  adn write it to the target locatiion .. and u can control the progress...

0
 

Author Comment

by:haggmar
ID: 10702455
ftp is not an option because this is not over the internet This is a Headquarter that distributes prices and information to all its stores. the stores do not have a webserver so i only ping the stores and copy the files over via intranet

I need som sample code


0
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 10702621

Ok .. then

create a file copy Procedure
  in procedure
  load ur source file in to a file stream ..
  and pump  ur source in to a target file stream ..
  tagret file stream must  be created in target folder..
   
  u can pump ur stream in small amounts of data .. and u can set ur progress bar while pumping data ..

  each time u pump .. increase the value of the progress bar

 u can use scripting.filesystemobject
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:haggmar
ID: 10702663
ok do tou have any sample code for this, i have never uses the scripting.filesystemobject before
0
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 10702763

here is a brief example
   
Dim msourObj As New Scripting.FileSystemObject
Dim mtargObj As New Scripting.FileSystemObject

Dim msourceFile As TextStream
Dim mtargetFile As TextStream


Set msourceFile = msourObj.OpenTextFile("c:\try.txt", ForReading, False)
Set mtargetFile = msourObj.CreateTextFile("\\192.168.33.11\c$\trycopy.txt", True, false)

counter = 0
While Not msourceFile.AtEndOfStream
   
   mtargetFile.WriteLine (msourceFile.ReadLine)
   counter = counter + 1
   MsgBox (Str(counter))
Wend

 
0
 

Author Comment

by:haggmar
ID: 10702808
hmmmm
will this only work for text files??

i am copying textfiles and zipfiles

0
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 10702833
Try 4 zip files...  if it doesnt work 4 zip files.. use standart VB openfile command for them
read in binary mode..
and write to a source file in binary mode again

0
 

Author Comment

by:haggmar
ID: 10702851
ok
u have sample code for that?
0
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 10703104
Dim tempvar(2048) As Byte
Open "c:\try.rar" For Binary As #1
Open "\\192.168.33.11\c$\try.rar" For Binary As #2
counter = 0
filelength = LOF(1)
dsize = CInt(filelength / 2048) - 1
For cnt = 1 To dszie
 Get #1, 2048, tempvar
 Put #2, , tempvar
 counter = counter + 1
 Next cnt
remainder = CLng(LOF(1) - (CLng((filelength / 2048) - 1) * 2048))
Get #1, remainder, tempvar
Put #2, remainder, tempvar

Close #1
Close #2
0
 

Author Comment

by:haggmar
ID: 10703200
doesnt work
the zipfile is corrupted after copying with this function
0
 
LVL 9

Expert Comment

by:bhagyesht
ID: 10703506
without a progress bar
"cmd.exe /c copy <source filename with path> <destination file name>
Bhagyesh Trivedi
0
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 10703511

i did not try it..
   change this  part

remainder = CLng(LOF(1) - (CLng((filelength / 2048) - 1) * 2048))
Get #1, remainder, tempvar
Put #2, , tempvar



0
 

Author Comment

by:haggmar
ID: 10703602
sorry
still the same error when opening the zipfile after copying

cannot open file: it does not appear to be a valid archive. If you downloaded this file, try downloading the file again.

the sourcefile work just fine

0
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 10703744

In this Code error  is  at the end..
try this instead

remainder = CLng(LOF(1) - (CLng((filelength / 2048) - 1) * 2048))
dim tmpdata(remainder)

  Get #1, remainder, tmpdata
  Put #2, , tmpdata
0
 

Author Comment

by:haggmar
ID: 10703868
same error occured ;(
but i had to change your code
as you wrote it it is wrong vb 6 syntax


I wrote dim tmpData() as byte
redim(tmpdata(remainder))

get #1, remainder, tmpdata
put #2, , tmpdata

any more ideas?

0
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 10703871
I ve tried this code .. and it works fine


Dim tempvar(2048) As Byte
Open "c:\try.rar" For Binary As #1
Open "\\192.168.33.11\c$\try.rar" For Binary As #2
counter = 0
filelength = LOF(1)
cnt = 0
dsize = CInt(filelength / 2048) - 1
For cnt = 1 To dsize
 Get #1, , tempvar
 Put #2, , tempvar
 counter = counter + 1
 Next cnt
remainder = CLng(LOF(1) - (CLng((filelength / 2048) - 1) * 2048))
Get #1, , tempvar
Put #2, , tempvar

Close #1
Close #2
0
 

Author Comment

by:haggmar
ID: 10703931
well the same code doesnt work for me
have you tried it on a .zip file and not a .rar file?

or any other ways of doing this?
0
 
LVL 19

Accepted Solution

by:
Melih SARICA earned 1000 total points
ID: 10703979
This Code works even while copying  exe files..

And i did try it.. in Ms Acces, Excell and Vb...
U use y copy paste the code correctly

***************************
Dim tempvar(2048) As Byte
Open "c:\try.zip" For Binary As #1
Open "\\192.168.33.11\c$\try.zip" For Binary As #2
counter = 0
filelength = LOF(1)
cnt = 0
dsize = CInt(filelength / 2048) - 1
For cnt = 1 To dsize
 Get #1, , tempvar
 Put #2, , tempvar
 counter = counter + 1
 Next cnt
remainder = CLng(LOF(1) - (CLng((filelength / 2048) - 1) * 2048))
Get #1, , tempvar
Put #2, , tempvar

Close #1
Close #2
*****************
0
 

Author Comment

by:haggmar
ID: 10704042
hmmmm
very strange
i tried it on a exefile and it worked fine
but not on my zip files

any ideas why??
0
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 10704107
try with an other zip file..

As u see its not deleting the Target zip file..

If there is a file with the same name.. &#305;ts appends the old file in the target path. adding source file at the edn of target file..

Delete target file first and then copy source file




0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question