Passing file name at runtime

i am trying to pass file name to a source procedure at runtime but not getting any sucess. can anyone guide me the right path to go?

Jason

DynamicFiles.zip (37.8 KB)

Try this prototype …
CopyFiles(*FILE SourceTableFile, *FILE DestinationTableFile)

and …
SourceTableFile{PROP:Name}

to either get or set the actual filename (depending on whether it’s open or not, see help for more info)

thanks julian. still getting error in passing the file name

Why don’t you use two STRING parameters to pass actual filenames for Source and Destination ?

CopyFiles(*FILE SourceTableFile, *FILE DestinationTableFile,STRING inSourceName,STRING inDestinationName)

In the process, i need to issue a open

Right now its
Open(sourcetablefile)

It cant take open(insourcename)?

FileNameA and FileNameB are reference variables of the &FILE time. Some correct reference to a FILE object must be assigned to a variable of the &FILE type before it can be used at the place of FILE. For example,

FileRef &FILE

FileRef &= NEW FILE
FileRef {PROP:Driver} = ‘DOS’
FileRef {PROP:Name} = FileName

See description of file drivers to find which properties and SEND commands are supported by particular driver. In general case, you need in some 3rd party library allowing to build file structure at run time.

Thanks also. May i know which third party options that are suitable for this?

You don’t need any third party tools to achieve this.

You already have files defined SourceTableFile and DestinationTableFile

So, you either assign filenames to them before you pass them to your CopyFiles procedure, or, you pass file names as well using additional STRING parameters.

So Option 1: Before calling CopyFiles

SourceFile{PROP:Name} = 'C:\SomeDirectory\FromName.tps'
DestinationFile{PROP:Name} = 'C:\SomeDirectory\ToName.tps'

Option 2: Additional STRING parameters to pass the names

CopyFiles(*File SourceFile,*FILE TargetFile,STRING fromName,STRING toName)

Inside CopyFiles …

SourceFile{PROP:Name} = fromName
DestinationFile{PROP:Name} = toName

Remember if these files don’t exist OPEN will fail, if DestinationFile is a new file, you should CREATE it.

SourceFile{PROP:Name} = fromName is not assigning the value to SourceFile.
It still remains empty. fromName contains the value

If SourceFile is already open (with an existing filename) you’ll have to CLOSE it before trying to assign a different name.

If fromName contains contains spaces, enclose it in double quotes:

fromName = '"' & CLIP(fromName) & '"'

image
source file value still empty. It should be CustomerA

If the program uses reference variables, something meaningful must be assigned to these variables before usage. In case of a reference variable of the &FILE type, the program must initialize it with some statically declared FILE structure, or use some expression having result of the *FILE type. Such expression can be:

  • value of some other reference variable of the &FILE type
  • result of a function returning result of the *FILE type
  • value returned by the NEW FILE statement

If the goal is to copy one file to another, both files must have the same structure. If the source file to copy can have arbitrary structure, the destination FILE structure must be taken from the source file. Hence, building of this structure at run time (=> usage of NEW FILE) is the only choice. The compiler generates the call to the Cla$NEW_FILE function for the NEW FILE statement. This function is exported from CLADF.DLL.
Then the program is need to import structure of the file on disk to both source and destination FILEs and then change the name of the destination file. Clarion has built-in way to import structure from existing file but, as far as I can see, it is not documented. So, it’s need to some 3rd party stuff for importing disk file structure or building this structure from the scratch.

If the program must just be able to make binary copies of files regardless their structure, it’s better to use the CopyFile or SHFileOperation API functions for ISAM files and SQL clause (may be dependent from particular server) for SQL files.

file structure of both file will be same. Yes, i need to build the files at runtime.
i have tried your method too.
FileRef &= NEW FILE
FileRef {PROP:Name} = CLIP(TLN:SourceTableName)
CopyTables(FileRef,FileNameB)

FileRef value is empty too.

There is no longer enough information here to help progress this.

I note you are calling your CopyFiles procedure inside a .TakeRecord, this implies that a table is already open so you shouldn’t open it again inside CopyFiles … perhaps you should check a file’s STATUS or have a serious re-think how you’re going about this.

As “Also” suggests, there are better methods for copying files, have a look at COPY(SourceFilename,DestinationFilename)

Setting FILE property is a function of the driver. If driver is not set, setting of FILE properties does nothing.

thank julian for your help and input. CopyFiles Procedure is called inside a Process where it loops a table that contains the file name value of source and destination.
COPY command is not suitable for what i am trying to do.

FileRef &= NEW FILE
FileRef {PROP:Name} = CLIP(TLN:SourceTableName)
FileRef {PROP:Driver} = ‘TOPSPEED’
CopyTables(FileRef,FileNameB)

FileRef still empty.

Does this syntax not require the Dynamic File Driver?

PROP:Driver must be set first.
Attached program shows importing the structure of the TPS file from the ZIP in the first topic’s message. I filled with X’s the line with invoking Clarion undocumented feature to import FILE structure. Images with messages boxes shown by this program:


test.clw (585 Bytes)

If the program uses NEW FILE, yes, the Dynamic File Driver is required. If some 3rd party stuff is using to import/create FILE structure at run time, necessity of CLADF depends from particular stuff. XLIB was not need in it.