Copy Files Using QB45

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
IanM
Newbie
Posts: 4
Joined: Wed Nov 08, 2006 7:45 am

Copy Files Using QB45

Post by IanM »

You will probably think me as stupid as a 286, and I have checked the FAQ section, but how can I copy a file from one part of my C:\ drive to another part of my C:\ drive using Quick basic - can it be done?

I can make files and folders - just not copy files...yet

any help or suggestions would be appreciated.

thank you.
IanM
Newbie
Posts: 4
Joined: Wed Nov 08, 2006 7:45 am

Post by IanM »

Its ok... I think its sorted

I assembled a String$ which was in the format "copy folder1/file1 folder2/file2"

then used SHELL String$

and things seem ok :)


if there is a better way please let me know.
sid6.7
Veteran
Posts: 318
Joined: Tue Jun 21, 2005 8:51 am
Location: west USA
Contact:

Post by sid6.7 »

are they just plain text files?
Plasma
Coder
Posts: 11
Joined: Tue Apr 04, 2006 7:28 pm

Post by Plasma »

Code: Select all

DECLARE SUB CopyFile (From$, To$)

SUB CopyFile (From$, To$)

  ' Open the input file in binary mode
  InFile = FREEFILE
  OPEN From$ FOR BINARY AS #InFile

  ' Open the output file
  ' (truncate it if it exists)
  OutFile = FREEFILE
  OPEN To$ FOR OUTPUT AS #OutFile
  CLOSE #OutFile

  ' Reopen the output file in binary mode
  OPEN To$ FOR BINARY AS #OutFile

  ' Copy the file
  DO WHILE NOT EOF(InFile)
    Buffer$ = INPUT$(4096, 1)
    PUT #OutFile, , Buffer$
  LOOP

  ' Close the files
  CLOSE #OutFile
  CLOSE #InFile

END SUB
IanM
Newbie
Posts: 4
Joined: Wed Nov 08, 2006 7:45 am

Thank You

Post by IanM »

deepest appologies - for not replying earlier, but thank you for your time. (and yes they were just text files)
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

Hi,

Back in 1990, I was confronted with the need to copy files from within a QB program. I played around with different methods that actually read and wrote the records from within the program. I discovered that there there were several sticky little problems that caused the filles not to be exactly the same. I haven't tried Plasma's version, but I have a feeling that this would have some of these problems.

Finally, I decided to do SHELL with the corresponding COPY command, as IanM suggests, and I have never had a problem since. I like this approach because you hand over the responsibility for the COPY, to DOS. A COPY, just like DOS does, is really what you want, so why try to emulate it.

Regards..... Moneo
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Add this to your list Moneo:

If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
If you posted something 3 years ago,
who is the dummy for answering it? :wink:
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

burger2227 wrote:Add this to your list Moneo:

If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
If you posted something 3 years ago,
who is the dummy for answering it? :wink:
You're right, Ted. That makes me a dummy. I went by the date of the last post, and didn't check the date of the original thread.

Well, live and learn.

Regards..... Moneo
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

In your defense, the previous poster was a little late replying. LOL

I'm glad you took my post as a joke and not an insult!

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
Seb McClouth
Veteran
Posts: 342
Joined: Wed Nov 09, 2005 7:47 am
Location: Inside the Matrix...
Contact:

Post by Seb McClouth »

More to defense: we're all dummies... whahoo!!
QBinux is a Linux distribution with the aim of integrating the work of the vast community of free software developers at Pete's QBASIC Site in order to create a modern, performant, safe and easy to use system for system administrators and desktop users.
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

Speak for yourself Seb..

I'm not a dummy, I'm just intellectually challenged. :lol:
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
User avatar
Seb McClouth
Veteran
Posts: 342
Joined: Wed Nov 09, 2005 7:47 am
Location: Inside the Matrix...
Contact:

Post by Seb McClouth »

well most of us are, therefor we're dummies :lol:
QBinux is a Linux distribution with the aim of integrating the work of the vast community of free software developers at Pete's QBASIC Site in order to create a modern, performant, safe and easy to use system for system administrators and desktop users.
IanM
Newbie
Posts: 4
Joined: Wed Nov 08, 2006 7:45 am

Post by IanM »

? what have I created.... ?

:)
bungytheworm
Veteran
Posts: 288
Joined: Sat Feb 18, 2006 4:02 pm

Post by bungytheworm »

The one who ignores and denies the fact he's a dummy, is the real dumb. I accept the fact im dummy, that makes me pretty darn wise.
? what have I created.... ?
You did not create anything, but for sure you did wake up something :lol:
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

At least nobody called him an A$$hole. What happened to your self-description anyhow?
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Post Reply