DEV Community

Peter + AI
Peter + AI

Posted on

πŸ“ Mastering Directory Creation in Uniface: The dircreate Statement

Working with directories is a fundamental aspect of many applications, and Uniface provides a powerful and flexible way to create directories through the dircreate statement. Let's dive into this essential ProcScript command! πŸš€

🎯 What is dircreate?

The dircreate statement creates a specified directory in the current working directory using any file redirections defined in the assignment file. It's a simple yet powerful command that can be used across all Uniface component types.

Basic Syntax

dircreate NewDirPath
Enter fullscreen mode Exit fullscreen mode

Simple Example

dircreate "exports"
Enter fullscreen mode Exit fullscreen mode

βš™οΈ Parameters and Configuration

The dircreate statement takes a single parameter:

Parameter Data Type Description
NewDirPath String Directory name, optionally preceded by the path to the directory. Must end with a directory separator.

πŸ“ Path Specifications

  • Maximum Length: 255 bytes for any path, file name, or directory name
  • Valid Separators: Backward slash (\), forward slash (/), and period (.) with square brackets ([a.b])
  • Input Types: String, field, variable, or function that evaluates to a string

πŸ”„ Return Values

The dircreate statement provides clear feedback through $procerror:

Value Error Constant Meaning
0 - βœ… Successful
-13 ❌ OS command error occurred

πŸ’‘ Pro Tip: Use /pri=64 to display the exact error message in the message frame when encountering OS command errors.

πŸ› οΈ Practical Examples

Creating a Directory in Current Working Directory

dircreate "coffee"
Enter fullscreen mode Exit fullscreen mode

Creating a Directory in an Existing Directory

dircreate "sub1dir/coffee/"
Enter fullscreen mode Exit fullscreen mode

Or using the alternative syntax:

dircreate "[.sub1dir.coffee.]"
Enter fullscreen mode Exit fullscreen mode

🚫 Common Failure Scenarios

The dircreate operation will fail if:

  • πŸ“‚ Directory already exists
  • πŸ”’ Insufficient authorization level
  • ❌ Invalid syntax
  • 🚷 Specifies the $RES path (e.g., "$RES:/NewDirPath")

πŸ–₯️ Platform-Specific Behavior

Unix Systems

On Unix, directories are created with read and write access for world, group, and user levels. 🐧

iSeries Systems

On iSeries, dircreate can create:

  • Without IFS prefix: Libraries or files in libraries (max one directory separator)
  • With IFS prefix: IFS directories with subdirectories (subject to file system rules)

πŸŽ‰ Best Practices

  1. Always check return values: Monitor $procerror for operation success
  2. Use proper separators: Leverage Uniface's cross-platform directory separators
  3. Handle errors gracefully: Implement proper error handling for failed operations
  4. Validate paths: Ensure paths don't exceed 255 bytes

πŸ” Conclusion

The dircreate statement is a versatile tool in the Uniface developer's toolkit. Whether you're organizing application data, creating export directories, or managing file structures, understanding this command will enhance your ProcScript capabilities. πŸ’ͺ

Remember to always validate your directory paths and handle potential errors appropriately. Happy coding! 🎯


Based on Uniface Documentation 10.4 | Created with AI assistance

Top comments (0)