Help File Copy 
Author Message
 Help File Copy

Why Wont This Copy Files Correctly
Say A (41.1 K) file is copied as A (17.0 K) File
What's Up With That!
This Code Looks Sound Any Help
note: Small files Like Txt, And Ini File copy OK
      But Larger Exe's Like The Size Above Don't

USERDATA$ = "C:\TEST1\"
BACKDATA$ = "C:\TEST2\"
NFILE$ = DIR$(USERDATA$,ZZ)
WHILE Len(NFILE$) > 0
source$ = USERDATA$ + NFILE$
dest$ = BACKDATA$ + NFILE$
CLOSE
OPEN source$ FOR BINARY AS #1
OPEN dest$ FOR BINARY AS #2
msg$ = SPACE$(LOF(1)) 'set msg$ string length to file length
GET #1, , msg$
LOCATE 14,25:COLOR 14, 9:PRINT "                                 "
LOCATE 14,27:COLOR 14, 9:PRINT USERDATA$;NFILE$
DELAY 0.3
PUT #2, , msg$
CLOSE 'both #1 and #2
NFILE$ = DIR$
WEND



Fri, 28 Nov 2003 14:44:55 GMT  
 Help File Copy

Quote:

>Why Wont This Copy Files Correctly
>Say A (41.1 K) file is copied as A (17.0 K) File
>What's Up With That!
>This Code Looks Sound Any Help
>note: Small files Like Txt, And Ini File copy OK
>      But Larger Exe's Like The Size Above Don't

Newbie,

  I ignored your first question and I've reservations about answering this one
but I'll give you one shot. I like to know who I'm talking to.

  Anyhow, the code below should get you in the ballpark. I assume you're using
one of the DOS BASICs as the Windoze versions have FILECOPY.

--
C'ya,
   ____    _    ____      ____  _____
  |  _ \  / \  / ___) __ | ___)(_   _)     Don Schullian

  |____//_/ \_\(____/\__/|_|     |_|  http://www.DASoftVSS.com
  ___________________________________ http://www.basicguru.com
      Vertical Software Solutions

$if 0
    ??????????????????????????                        powerbasic v3.50
 ??          DASoft          ??????????????????????????????????????????
 3  ????????????????????????????    Copyright 1998    3 DATE: 1998-01-31 ??
 3  3 FILE NAME   COPYFILE.UNT o          by          ?? o o
 3  3 LIBRARY     DAS-NB02.PBL o  Don Schullian, Jr.                     o o
 3  ??                                         o o
 3 A license is hereby granted to the holder to use this source code in  o o
 3 any program, commercial or otherwise,  without receiving the express  o o
 3 permission of the copyright holder and without paying any royalties,  o o
 3 as long as this code is not distributed in any compilable format.     o o
 3  IE: source code files, PowerBASIC Unit files, and printed listings   o o
 ??? o
   ??
$endif

'.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?
' ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
' PURPOSE: to copy a file like DOS's COPY
'  PARAMS: FromFile$ D:\PATH\FILENAME.EXT to copy from
'            ToFile$ D:\PATH\FILENAME.EXT to copy to
' RETURNS: DOS's error message if file was NOT copied
'          elsewise ZERO
'.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?
' ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

FUNCTION fCopyFile ( SEG FromFile AS STRING, _
                     SEG ToFile   AS STRING  ) AS INTEGER

  DIM Bytes    AS LOCAL LONG
  DIM Chunk    AS LOCAL INTEGER
  DIM FF1      AS LOCAL INTEGER
  DIM FF2      AS LOCAL INTEGER
  DIM MaxBytes AS LOCAL INTEGER
                                                  '????????????????????????
  ON LOCAL ERROR GOTO CLOSEFILEOOPS               '3 local error trap
    IF LEN(DIR$(FromFile$)) = 0 THEN ERROR 53     '3 "FILE NOT FOUND"
    FF1% = FREEFILE                               '3 open from-file
    OPEN "B", #FF1%, FromFile$                    '3
    Bytes& = LOF( FF1% )                          '3 length of from-file
                                                  '3
    FF2% = FREEFILE                               '3 open/create to-file
    OPEN "B", #FF2%, ToFile$                      '3
                                                  '3
    MaxBytes% = ( FRE(-4) AND &h7E00 )            '3 max string length
                                                  '3 rounded to 512
    WHILE Bytes& > 0                              '3 hit it!
      Chunk% = MIN( MaxBytes%, Bytes& )           '3
      GET$ #FF1%, Chunk%, D$                      '3
      PUT$ #FF2%, D$                              '3
      DECR Bytes&, Chunk%                         '3
    WEND                                          '3
    SETEOF #FF2                                   '3
                                                  '3
  CLOSEFILEOUT:                                   '3
    IF FF2% > 0 THEN CLOSE FF2%                   '3 close #2
    IF FF1% > 0 THEN CLOSE FF1%                   '3 close #1
  EXIT FUNCTION                                   '3
                                                  '3
  CLOSEFILEOOPS:                                  '3
    FUNCTION = ERRTEST                            '3 oops! got an error here
    RESUME CLOSEFILEOUT                           '3 bail out!
                                                  '?????????????????????????
END FUNCTION



Sat, 29 Nov 2003 11:54:23 GMT  
 Help File Copy
Copying files in "byte" sized chunks in incredibly inefficient,
especially if you are going to do this across a network.

Assuming you want to use BINARY mode to read and write the data, the
general "rule of thumb" is to use 8kb (8192 byte) chunks - this
provides the most network-friendly data transfer, while still
providing a good effficiency level.  

BTW, as a PB/DOS user, you may wish to take a look in the DOSUNIT.BAS
code in the PBDOS\EXAMPLE\ folder - there is complete code for a
FILECOPY routine that uses the internal DOS copy function to do the
work, without the need to use SHELL or raw BINARY mode file transfers.

I hope this helps!

Quote:

>Ok!
>One More Question Is It socially acceptable to shell out multiple
>times in a dir$ loop to copy it this the politically correct way to copy
>Since most basic books seam to skip this file copy questions
>they answer how to create, open, close, append, lock and so on!

Lance
PowerBASIC Support

-------------------------------------------------------------------------
PowerBASIC, Inc.      | 800-780-7707 Sales | "We put the Power in Basic!"
316 Mid Valley Center | 831-659-8000 Voice | http://www.powerbasic.com



Mon, 01 Dec 2003 16:57:42 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. CW2.003 File copy changes the date.....need a way to copy w/o date change

2. BUG: file copy copies links as links

3. Help Copy Files

4. Help With File Copy

5. Need help copying a file to the printer

6. help copy file

7. Help on copy file

8. Help, need to copy a 1474560 (1.404M) byte file to floppy disk

9. Need help - expect script: Copy a file from tftp server to cisco router flash

10. HELP: how to copy binary files?

11. searching and copying text in a file - please help

12. Please Help: Copying files using GS-VW

 

 
Powered by phpBB® Forum Software