Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XCOPY-DOS type function with VFP

Status
Not open for further replies.

foxup

Programmer
Dec 14, 2010
328
CA
Hi,

Is there a variant of the VFP "COPY FILE" command where I can copy files that have changed on or after the specified date ?

Example in DOS:
XCOPY *.*/D:m-d-y

Example in VFP:
COPY FILE /D or something of the sorts? What would be the paramters in VFP if any?

I don't see anything in the VFP HELP FILE.

Please let me know.


Thanks,
FOXUP !


 
Nevermind. I found it using FDATE...LOL.

Thanks everybody ;)
 
Not with just COPY FILE. YOu could use ADIR() to retrieve info about the files in a folder and then loop through to find only the ones of interest.

Tamar
 
Hi All,

It seems there was a bug in my logic when I use "FDATE". This command does not yield the proper response:

COPY FILE R:\CDR\DES\deactivate_es_daily????????.dbf TO C:\QEns_Deacts for fdate>periods.pfrom

I've checked the fdate of the file and it's 26/04/2019. Ive checked the periods.pfrom, it's 01/05/2019, YET it gets copied ??? Im wondering if the "FOR" in the above statement doesn't get processed?

Please help with this one.


Thanks,
FOXUP!

 
COPY FILE doesn'T have a FOR clause, COPY TO does, but that needs a workarea as source.

Code:
IF FDATE('whatever')>FDATE('somethingelse')
   COPY FILE whatever to somethingelse
ENDIF

It's much more reliable to use xcopy or robocopy, though.

Bye, Olaf.

Olaf Doschke Software Engineering
 
No, your COPY FILE won't work, for two reasons. First, the command doesn't take a FOR clause. And secondly, if it did take a FOR clause, it still wouldn't work, because it would have no way of knowing that the date your are using is the file's date. Put another way, there is no connection between the COPY FILE command and the FDATE() function.

The only solution (as Tamar suggested) is to use ADIR() to get the dates of all the files that meet your specification into an array. You then loop through the resulting array, looking for those files with the required date condition. You then copy those files individually.

It's a little more complicated than using COPY FILE, but still only needs a few lines of code.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you Olaf, I was just reading the exact HELP documentation and wasn't seeing any clause for it.

How can I duplicate this in an DOS-XCOPY command?

COPY FILE R:\CDR\DES\deactivate_es_daily????????.dbf TO C:\QEns_Deacts for fdate>periods.pfrom AND fdate<=periods.invoicedat+1


Any suggestions?


Thanks,
FOXUP
 
Hi Mike,

I understand but was hoping to achieve it thru XCOPY (Dos) or COPY FILE command (VFP) without the ADIR method.

can you assist in the DOS-XCOPY ?


Thanks,
FOXUP!
 
Can you simple please reread? Yes, there is NO for clause. Right. You can't put a condition into the COPY FILE command. I gave you the code, an IF statement, which only does COPY FILE, when the filedate is newer.
You can't use a file name skeleton (with ? or *) for this, you have to loop all the single files.

Bye, Olaf.

Olaf Doschke Software Engineering
 
You've changed the spec. You originally asked about ccopying files that had changed after a certain date, which is easy with XCOPY. But now you want to copy files that have changed between two dates. As far as I know, that's not possible with XCOPY.

To copy files that have changed after a given date (periods.pfrom in this case), you would first have to convert the date to MM-DD-YYYY format, like so:

Code:
SET MARK  TO "-"
SET DATE AMERICAN
SET CENTURY ON
lcDate = DTOC(periods.pfrom)

Then construct and run the XCOPY command:

Code:
lcCommand = "XCOPY R:\CDR\DES\deactivate_es_daily????????.dbf C:\QEns_Deacts /d " + lcDate
RUN &lcCommand

I'm assuming XCOPY takes American date settings. I don't know if that is true in all locales, but you should be able to determine that with a little trial-and-error.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
But I still think it would be easier to use ADIR(). Plus that would also let you test for files modified between two dates.

Something like this:

Code:
lnCount = ADIR(laTemp, "R:\CDR\DES\deactivate_es_daily????????.dbf")
FOR lnI = 1 TO lnCount
  IF BETWEEN(laTemp(lnI, 3), periods.invoicedat+1, periods.pfrom)
    COPY FILE (laTemp(lnI, 1)) TO  C:\QEns_Deacts
  ENDIF 
ENDFOR

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
OK, thank you all, Ive gone with the ADIR() to achieve it. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top