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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use DOS Move for Multiple files from directory to directory in Foxpro program 1

Status
Not open for further replies.

eboughey1008

Programmer
Jan 6, 2009
31
0
6
US
This is simplistic and wrong but I'm trying to move the files instead of copying them if possible. I'm doing it all by hand right now.

**** SIMPLE BEGINNING *****

@ 11,5 say 'Enter Job Number for Return NCOA file: ' get CLIST_NO
READ
CLEAR
SET SAFETY OFF
SET TALK OFF

lcprefix = "e:\working\jobs\"+alltrim(CLIST_NO)+"\"
SET DEFAULT TO "e:\working\jobs\"+alltrim(CLIST_NO)+"\"

***** what I want to accomplish ****

1. Move files with the following info in the filename to my job directory
2. Remove part of the filename from the pdf files (.csv.export.csv.) after they are moved over.

this is just a simple command of how I'm trying to think the command through:

MOVE all instances of files with the (CLIST_NO) AND ".CSV.EXPORT" IN THE FILENAME TO MY JOB DIRECTORY

lcmove = "E:\WORKING\TRUENCOA\EXPORT\NCOA-"+ALLTRIM(CLIST_NO)+".CSV.EXPORT"+.*

!MOVE alltrim(lcmove) ALLTRIM(LCPREFIX) *** obviously doesn't work *****

I'm not sure at all that you can even move all instances of filenames that match or use [highlight #FCE94F]*.*[/highlight] in the command

what the filenames look like. There are always these 3 and
e:\working\truencoa\export\NCOA-52990.CSV.EXPORT.CSV ---- FILENAME STAYS THE SAME
e:\working\truencoa\export\NCOA-52990.CSV.EXPORT.CSV.CASS.PDF ---- ".CSV.EXPORT" IS REMOVED
e:\working\truencoa\export\NCOA-52990.CSV.EXPORT.CSV.NCOA.PDF ---- ".CSV.EXPORT" IS REMOVED


******************** PERHAPS ********************

lcmove = ""E:\WORKING\TRUENCOA\*+ALLTRIM(CLIST_NO)+".CSV.EXPORT.CSV"
lcmoveCASS = ""E:\WORKING\TRUENCOA\*+ALLTRIM(CLIST_NO)+".CSV.EXPORT.CSV.CASS.PDF"
lcmoveNCOA = ""E:\WORKING\TRUENCOA\*+ALLTRIM(CLIST_NO)+".CSV.EXPORT.CSV.NCOA.PDF"

!MOVE alltrim(lcmove) ALLTRIM(LCPREFIX) *** obviously doesn't work *****
!MOVE alltrim(lcmoveCASS) ALLTRIM(LCPREFIX)
!MOVE alltrim(lcmoveNCOA) ALLTRIM(LCPREFIX)

Any help would be so wonderful! I have been working on this for too long... I always have issues with the dos commands inside a foxpro program. You'd think I'd be a pro after all the times I've asked for help on this...
 
The MOVE help tells: The source can include wildcards (but not the destination).

Renaming is possible "on the move", but then source can't have wildcards. Is ADIR available? Then you can use it to determine names, apply a STRTRAN() to remove unwanted file name parts and generate a batch of file moves or run them one by one.

Chriss
 
So I was hoping this code would work but it doesn't. It compiles okay but doesn't do anything.... I've used /N and nothing. Didn't have the word 'to' originally. Didn't seem to matter. Any advice?

I can type the command in DOS by naming the file and giving the physical path and that works...

*** move test-copy.csv e:\working\jobs\52990-t3\ ***


CLOSE ALL
CLEAR
SET DELETED OFF


CLIST_NO = SPACE (15)

@ 11,5 say 'Enter Job Number for Return NCOA file: ' get CLIST_NO
READ
CLEAR
SET SAFETY OFF

SET TALK OFF

lcprefix = "e:\working\jobs\"+alltrim(CLIST_NO)+"\"
SET DEFAULT TO "e:\working\jobs\"+alltrim(CLIST_NO)+"\"

*** MOVE NCOA AND CASS FILES TO JOB DIRECTORY ******

lcmove = "E:\WORKING\TRUENCOA\EXPORT\"+"NCOA-"+LEFT(CLIST_NO,5)+".CSV.EXPORT.CSV"
lcmoveCASS = "E:\WORKING\TRUENCOA\EXPORT\"+"NCOA-"+LEFT(CLIST_NO,5)+".CSV.EXPORT.CSV.CASS.PDF"
lcmoveNCOA = "E:\WORKING\TRUENCOA\EXPORT\"+"NCOA-"+LEFT(CLIST_NO,5)+".CSV.EXPORT.CSV.NCOA.PDF"

RUN MOVE alltrim(lcmove) TO ALLTRIM(LCPREFIX) *** obviously doesn't work *****
RUN MOVE alltrim(lcmoveCASS) TO ALLTRIM(LCPREFIX)
RUN MOVE alltrim(lcmoveNCOA) TO ALLTRIM(LCPREFIX)
 
Going crazy here....

If I type in the physical location it works... using the below...

*!move *export* e:\working\jobs\52990-t3\ - works

lcmove = "e:\working\jobs\"+clist_no (doesn't do anything when i use the move command but doesn't crash)

!move *export* "e:\working\jobs\"+LEFT(clist_no,5) (doesn't do anything but doesn't crash)

so how can i get a dos command to work? Should I create a .bat file and run it instead?


 
I would use the batch file first, it would give you a chance to see if your strings contain what you want... and mean you could run the batch file
manually to check the operation.

But, to be honest it's gonna look clumsy anyway, so moving forward I would switch to using the Windows API

Code:
*!******************************************************************************
FUNCTION MOVE_FILE
	PARAMETERS m.FROMFILE,m.TOFILE
	PRIVATE m.FROMFILE,m.TOFILE,m.RETVAL
	DECLARE INTEGER MoveFile IN Win32API STRING SOURCE, STRING destination
	m.RETVAL = MOVEFILE(m.FROMFILE,m.TOFILE)
	CLEAR DLLS "MoveFile"
	RETURN(m.RETVAL)

It's cleaner, has a failure flag and does the job with no flashing screens, dos boxes or whatever.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
I guess you can't run Win32 API calls in fox for dos or foxbase, even if this runs on a windows host within a DOS or DOS emulatr, right?

You expect VFP first evaluates ALLTRIM and puts the result value into the RUN call.

It doesn't, it will pass everything after RUN as is.

Code:
lcFile = GetFile("txt")
RUN /N more lcFile

The only chance to pass something to a DOS command used by RUN is macro substitution, this always comes first, also here before even executing RUN.

I bet you already are at a batch file solution and I'd opt for it even when you could make a RUN solution work. As Griff already said the batch allows you to see what will be or has been done. Ok, looking into the source and target folder also does, but when the batch errors you don't just have the error but the commands as they were executed.

Griffs idea has some advantages, though, if it works within the EXE, whether directly or whether you compile an EXE expecting commandline parameters for a source file pattern and target directory. Just let main.prg of that helper EXE start with LPARAMETERS. There you can make use of ADIR and Win32API, MoveFile or MoveFileEx.

Chriss
 
I suppose I should have guessed his version based on the @ say get...

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
I really don't know, Griff, @ say also works in VFP9 run on Windows. The only indicator is the DOS move command usage. Foxbase was mentioned in another thread lately.
If this originally was DOS and is ported to VFP9 using its backward compatibility it might be run on DOS emulator or it might have been adapted to become a Winforms application as usual VFP exdecutables.

Chriss
 
Good thought, Steve,

especially when you're sure the target files don't exist and the target directory is on the same drive/partition/volume.

MoveFileEx has some flags that may make this more secure. At minimum you have the return value stating failure or success and a VFP command never has a result value, just the result of the commanded action.

Chriss
 

Chris said:
especially when you're sure the target files don't exist and the target directory is on the same drive/partition/volume.

Very true. Perhaps some combination of RENAME, COPY FILE & DELETE FILE might work. I think those commands are available in (very) old versions.

Steve
 
I would always use RENAME for this type of operation. When you use RENAME to give a file a new path name, you are in effect moving the file to the new path. Not only is this simpler than copying and deleting, but it is much faster, especially for large files.

And with RENAME, both the source and the destination files can include wildcards.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I still think MoveFileEx has more interesting options, but target name wildcrds, what can you actually do with them? What will ? and * expand to, their wildcard meaning is "anything", one or more characters of anything. Does VFP take the first * part found in the source name and replaces that in the first * on the target filename? I can of course test this for myself, but I'd like you to expand on this, Mike.

You always learn something new.

Okay, reading the helpt topic an example given is

Code:
RENAME *.prg to *.bak

After some tests it works. I created some files test1.export.csv.txt to test3.export.csv.txt and...
Code:
RENAME test?.export.csv.txt to ..\test?.txt
...moved them to the parent directory and only kept the number (the ?).

That solves at least a part of the problem.

Eboughey1008, you also wanted to keep .export.csv in one of the files, so that needs a separate first RENAME only copying the first file.

Chriss
 
Mike L. said:
I would always use RENAME for this type of operation.

I would too, but as Chris pointed out RENAME alone would not cross devices. I confirmed that with testing. I don't know if that's the case here, though.

If it is, using COPY FILE & DELETE FILE could solve that. However, if number of files or file size were large, speed could be a problem, leading toward Chris's solution.

Steve
 
Steve and Chris,

Yes, I take the point about RENAME not crossing devices (or drives). After all, all that RENAME does is change a pointer in a directory. That's what makes it so fast. But of course that is only useful if the old and new names are in the same physical place.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
MoveFileEx offers a flag to use copy&delete, only if needed. So you wouldn't have to worry. But it all depends on what works with the application. I think the wish to use the DOS MOVE command hints on moving files on the same drive just to another folder, and when this directory would be newly created there would be no reason to use something more complex than RENAME.

I think eboughey1008 will pick this up on Monday and there is plenty of information to consider in the choice.

Chriss
 
Wow there is a lot of info to digest here...

I'm going to work on this tonight and will update on final working version in the morning.

BTW, I have VFP9 - I'm just a very old "manipulator of code" so I still use some really old code. Oh and I'm a 'her' :)
 


This was so easy after I read the different changes I could make.... The RENAME function did it all in one pass.. The naming of the files is always the same, the locations are on the same drive and the files are never going to overwrite another so this was a perfect solution.

I was even able to archive the original file so my export directory stays clean and organized. I'd been moving files over manually every week. I can see a lot of uses for this command in my current programs.

You guys are the ABSOLUTE BEST SUPPORT GROUP EVER!!! Special Shout out to Mike Lewis

rename "E:\WORKING\TRUENCOA\EXPORT\"+"NCOA-"+LEFT(CLIST_NO,5)+".CSV to "E:\WORKING\TRUENCOA\EXPORT\ARCHIVE\"+"NCOA-"+LEFT(CLIST_NO,5)+".CSV
rename "E:\WORKING\TRUENCOA\EXPORT\"+"NCOA-"+LEFT(CLIST_NO,5)+".CSV.EXPORT.CSV" to alltrim(lcprefix)+"NCOA-"+LEFT(CLIST_NO,5)+".CSV.EXPORT.CSV"
RENAME "E:\WORKING\TRUENCOA\EXPORT\"+"NCOA-"+LEFT(CLIST_NO,5)+".CSV.EXPORT.CSV.CASS.PDF" to alltrim(lcprefix)+"CASS Report - JOB-"+LEFT(CLIST_NO,5)+".PDF"
RENAME "E:\WORKING\TRUENCOA\EXPORT\"+"NCOA-"+LEFT(CLIST_NO,5)+".CSV.EXPORT.CSV.NCOA.PDF" to alltrim(lcprefix)+"NCOALink® Processing Summary Report - JOB-" + LEFT(CLIST_NO,5)+".PDF"
 
Okay, you're not making use of wildcards here, but good that Steve mentioned RENAME and Mike also recommended it.

Chriss
 
FWIW (nothing) I would have thought the long expressions for file names would need to be inside ( )s. But I guess not (didn't test).[ponytails]

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top