DEV Community

Peter + AI
Peter + AI

Posted on

πŸš€ Mastering File Operations in Uniface: The filemove Statement Guide

Hey fellow developers! πŸ‘‹ Today I want to share some insights about file operations in Uniface, specifically the filemove statement. This comprehensive guide is based on the official Uniface Documentation 10.4, and I've got some help from AI to structure this content for you.

πŸ“‹ What is filemove?

The filemove statement is a powerful Uniface command that allows you to move files from one location to another. It's more flexible than you might think - you can move files between directories, rename them during the move, and even work with ZIP archives! πŸ“¦

πŸ”§ Syntax and Parameters

The basic syntax is straightforward:

filemove FilePath, DirPath | NewFilePath
Enter fullscreen mode Exit fullscreen mode

Parameters Breakdown:

Parameter Type Description
FilePath String Source file path (must not end with directory separator)
DirPath String Target directory path (must end with directory separator)
NewFilePath String New file path for move + rename (must not end with directory separator)

βœ… Return Values

The filemove statement returns different values through $procerror:

  • 0: Success! πŸŽ‰
  • -13: OS command error (use /pri=64 to see details)

πŸ’‘ Practical Examples

Simple Move to Another Directory

filemove "sub1dir/test.txt", "sub1dir/sub2dir/"
Enter fullscreen mode Exit fullscreen mode

Or using bracket notation:

filemove "[.sub1dir]test.txt", "[.sub1dir.sub2dir]"
Enter fullscreen mode Exit fullscreen mode

Move + Rename in One Operation

filemove "./test1.txt", "./sub2dir/text.txt"
Enter fullscreen mode Exit fullscreen mode

Pro Tip: πŸ’‘ The presence or absence of the trailing directory separator determines whether you're just moving or also renaming!

πŸ—œοΈ Working with ZIP Archives

One of the coolest features of filemove is its ability to work with ZIP archives. You can:

  • Move files within the same ZIP archive
  • Move files between different ZIP archives
  • Move files from ZIP archives to local directories
  • Move files from local directories to ZIP archives

⚠️ Important Considerations

File Path Limitations

  • Maximum path length: 255 bytes
  • No wildcards allowed (except for specific directory functions)
  • Multiple directory separator formats supported

Cross-Platform Behavior

Uniface automatically handles text file conversions when moving files across platforms, adjusting EOL characters and character sets. Binary files are copied as-is. 🌐

Common Failure Scenarios

  • Source file doesn't exist or isn't a file
  • Target directory doesn't exist or lacks write permissions
  • Target file already exists
  • Invalid syntax in path specifications

🎯 Best Practices

  1. Always check $procerror after file operations
  2. Use forward slashes for cross-platform compatibility
  3. Ensure target directories exist before moving files
  4. Handle file collisions by checking if target files exist
  5. Consider using filerename for simple rename operations

🏁 Conclusion

The filemove statement is an essential tool in the Uniface developer's toolkit. Its flexibility with ZIP archives, cross-platform support, and simple syntax make it perfect for file management tasks in your applications. Remember to always handle errors properly and consider the specific requirements of your target platform! πŸš€

Happy coding! πŸ‘¨β€πŸ’»πŸ‘©β€πŸ’»

Top comments (0)