Movefile

Started by Nicola, October 23, 2023, 09:40:17 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Nicola

The problem is not emulating DOS, the problem is because the variables behave outlily. If I run a cycle from 1 to 30, why does it get stuck at a certain point?
Why if I use copyfile(sorgente,destinazione)   program crashes?
Why if I use copyfile(dirsource + "\" + d[ix],dest + d[ix]) copy only 10 of 30 files?

Charles Pegge

Hi Nicola,

I found that CopyFile takes 3 parameters. The last param would normally be set to 0.

https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-copyfile

BOOL CopyFile(
  [in] LPCTSTR lpExistingFileName,
  [in] LPCTSTR lpNewFileName,
  [in] BOOL    bFailIfExists
);

Also: Redim string d[100] should be placed in global space outside the xxcopy function

Everything else looks ok. But it took me a few hours to isolate these bugs, so my mental health also needs restoration :)

John Montenigro

Here's how I handled a quirk in the backup process years ago...

how to keep file creation date when doing backups

I hope this is helpful!
-John
  •  

Nicola

Well done Charles,
how did you figure out that Redim string d[100] had to be put out of function even though I only use array d in the function?
Anyway, I was sure you had found the catch.

Now it seems to be working well.

uses sysutil


redim string d[100]

function xxCopyFile(string source, string dest, int muove=0) as int
===================================================================
string cr=chr(13,10)
int i, max, h

string lista, w, sorgente, destinazione, dirsource
int c  'files count

dirsource=extractdirname(source)
lista =  getfilelist source,c
'print lista cr c
max=c
'd è il vettore dove vanno i dati splittati, c è il  numero di dati trovati
split(lista,d,max,h,w)
'string listone=d[1]
'for i=2 to c
'  listone = listone+ ";" + d[i]
'next
'print listone+"#"
'print "c=" c "- " max
int ix=0
do
  ix++ : if ix>max then exit do
  sorgente=dirsource + "\" + d[ix]
  'print dirsource + "\" + d[ix]
  destinazione=dest + d[ix]

  copyfile sorgente,destinazione,0

  if muove<>0 then
    deletefile(sorgente)
  end if
end do
return ix-1
  '
end function
'-------------------------------------------

string ff
string sorg=curdir+"\*.tmp"
string desti=curdir+"\n\"
createdirectory(desti)
'print sorg cr desti
int g
for g=1 to 30
 ff=g+".tmp"
 putfile ff,"helo"
next

print XXcopyFile(sorg,desti,1) 'if the third element is non-zero make the move otherwise only copy

p.s. Charles
... A good beer can be useful :-)

Charles Pegge

#19
Thanks for the link John.

I found that with the code we are testing here, the date modified is conserved but the date created is the date of copying.

Hi Nicola,,
I need to investigate the redim problem further.. It should create a static array when defined within a procedure. But in general, the array should have a unique name in the program,, and if it is globally defined it can be redimmed from any procedure.

Nicola

Great Charles, thank you.

Thanks for the link John.