Working with file operations in Uniface? The filerename
statement is your go-to tool for renaming files within the same directory. Let me walk you through everything you need to know about this useful function! π
This article is based on the Uniface Documentation 10.4 and was created with the assistance of AI to provide you with a comprehensive overview.
π§ Basic Syntax
The filerename
statement follows a simple syntax:
filerename FilePath, NewFileName
Here's a quick example:
filerename "sub1dir/test.txt", "tested.txt"
π Parameters Breakdown
Parameter | Data Type | Description |
---|---|---|
FilePath |
String | File name with optional path. Must not end with directory separator |
NewFileName |
String | New file name only. No path included, no directory separator at end |
β Return Values
- 0: Success! π
- -13 (UIOSERR_OS_COMMAND): OS command error occurred π¨
Pro tip: Set /pri=64
to display the exact error message in the message frame when troubleshooting! π‘
π― Key Features
π File Location Flexibility
- Works with any file redirections in the assignment file
- Supports renaming files within ZIP archives
- Can be used in all component types
π£οΈ Path Specifications
You can specify file names using:
- String literals
- Field references (direct or indirect)
- Variables
- Functions that evaluate to strings
Important: Path length must not exceed 255 bytes! π
β οΈ Common Pitfalls
The operation will fail if:
π Source File Issues
- File doesn't exist
- Path points to a directory, not a file
- File is currently in use (locked)
- Insufficient authorization level
- Invalid syntax
π― Target File Issues
- New filename already exists
- Invalid syntax in new filename
- Attempting to use $RES path for NewFileName
πΌ Practical Examples
Standard Usage
filerename "sub1dir/test.txt", "tested.txt"
Alternative Syntax
filerename "[.sub1dir]test.txt;5", "tested.txt"
Using with Resources Deployment Path ($RES)
filerename "$RES:sub1dir/test.txt", "tested.txt"
β οΈ Important: Only use $RES with FilePath, never with NewFileName!
π₯οΈ Platform-Specific Notes
iSeries Considerations
On iSeries systems, changing a file's extension implies moving a member to a different file. For example:
filerename "lib/aaa.ext1", "bbb.ext2"
This moves member aaa
from file ext1
to file ext2
and renames it to bbb
. The target file must already exist with appropriate access rights! π
π Conclusion
The filerename
statement is a powerful and straightforward tool for file management in Uniface. Remember the key points:
- Only renames within the same directory
- NewFileName should not include path information
- Always check return values for error handling
- Be mindful of platform-specific behaviors
Happy coding! π»β¨
Top comments (0)