Working with files is a fundamental part of many applications, and Uniface provides a powerful filecopy
statement that makes file manipulation straightforward and reliable. Let me walk you through everything you need to know about this essential command! π»
This article is based on the official Uniface Documentation 10.4, and I had assistance from AI in structuring this comprehensive guide.
π― What is filecopy?
The filecopy
statement in Uniface allows you to copy files from one location to another with impressive flexibility. Whether you're working with local files, ZIP archives, or cross-platform scenarios, this command has you covered!
π Basic Syntax
filecopy FilePath, DirPath | NewFilePath
π§ Parameters Breakdown
- FilePath (String): Source file name with optional path (no trailing directory separator)
- DirPath (String): Target directory with optional path (must end with directory separator)
- NewFilePath (String): New file name with optional path (no trailing directory separator)
β¨ Practical Examples
π Copy to Another Directory
; Copy test.txt to a different directory
filecopy "data/test.txt", "data/saved/"
; Using alternative syntax
filecopy "[.sub1dir]test.txt", "[.sub1dir.sub2dir]"
π Rename While Copying
; Copy and rename in the same operation
filecopy "sub1dir/test1.txt", "sub1dir/test2.txt"
; Copy to different directory with new name
filecopy "test1.txt", "./sub3dir/test2.txt"
π Advanced Features
π¦ ZIP Archive Support
One of the coolest features is ZIP archive support! You can:
- Copy files from ZIP archives to file system β¬οΈ
- Copy files into ZIP archives β¬οΈ
- Move files between different ZIP archives π
- Reorganize files within the same ZIP archive π
π Cross-Platform Intelligence
Uniface automatically handles platform differences:
- Text files: Automatic EOL character conversion and character set handling π
- Binary files: Copied as-is without modification πΎ
- Configure behavior using
$TEXT_FILE_EXTENSIONS
setting βοΈ
π¨ Error Handling
Always check $procerror
for operation results:
-
0
: Success! β -
-13
: OS command error (use/pri=64
for detailed error info) β
β οΈ Common Failure Scenarios
- Source file doesn't exist or isn't a file
- Target directory doesn't exist
- Insufficient permissions
- Target file already exists
- Invalid path syntax
π‘ Pro Tips
π‘οΈ Best Practices
- Always validate paths: Keep path lengths under 255 bytes
- Use proper separators:
\
,/
, or[.directory]
format - Check permissions: Ensure write access to target locations
- Handle errors gracefully: Always check
$procerror
π¨ Flexible Path Specifications
You can use various input types:
- String literals
- Field references
- Variables
- Functions that return strings
π― Use Cases in Real Applications
- Backup operations: Regular file backups with timestamp suffixes
- Data processing: Moving processed files to archive directories
- Template management: Copying template files for customization
- Log rotation: Archiving old log files
- Deployment scripts: Copying configuration files between environments
π Conclusion
The filecopy
statement in Uniface is a robust, feature-rich tool that handles file operations with elegance and reliability. Its support for ZIP archives, cross-platform compatibility, and flexible syntax makes it an invaluable asset for any Uniface developer. π
Whether you're building backup systems, data processing pipelines, or simple file management utilities, filecopy
provides the foundation you need to handle files professionally and efficiently!
Have you used filecopy in interesting ways? Share your experiences in the comments below! π¬
Top comments (0)