Working with directory operations in Uniface can be tricky, especially when you need to safely delete directories. Today, let's explore the dirdelete
command and learn how to use it effectively! 🚀
This article is based on Uniface Documentation 10.4 and was created with AI assistance to help fellow developers navigate this powerful feature.
📋 What is dirdelete?
The dirdelete
statement in Uniface is used to delete specified directories. It's a powerful command that respects file redirections in your assignment file and provides proper error handling.
🔧 Basic Syntax
dirdelete DirPath
Example:
dirdelete "data/exports"
⚙️ Parameters
Parameter | Data Type | Description |
---|---|---|
DirPath | String | Directory name, optionally preceded by the path to the directory, which can be in a zip archive. Must end with a directory separator. |
🔍 Return Values
The command returns specific values through $procerror
:
Value | Error Constant | Meaning |
---|---|---|
0 | - | ✅ Successful |
-13 | <UIOSERR_OS_COMMAND> | ❌ An error occurred while trying to perform the OS command. Set /pri=64 to display the exact error in the message frame. |
🎯 Usage Guidelines
📁 Directory Specification
- Flexible Input: Can be a string, field, variable, or function that evaluates to a string
- Path Length: Maximum 255 bytes for any path/directory name
- Directory Separators: Supports
\
,/
, and[a.b]
notation - Wildcards: Generally not allowed (except for
$ldirlist
and$dirlist
)
⚠️ Operation Failure Conditions
The operation will fail if the directory:
- 🚫 Is not actually a directory
- 🏠 Is the current directory or root
- 📦 Is not empty
- 🔒 Is in use (locked)
- 🔐 Doesn't permit user-deletion due to insufficient authorization
- ❌ Has invalid syntax
💡 Practical Example
Here's a real-world example that demonstrates safe directory deletion with user confirmation:
$dir$ = "drinks/tea/" ; Alternative notations: ; $dir$ = "drinks/tea/" ; $dir$ = "[drinks.tea]" if ($dirlist($dir$,"dir") = "" & $dirlist($dir$,"file") = "") askmess/warning "Do you want to delete '%%$dir$'?", "Yes, No" if ($status = 1) dirdelete $dir$ endif else message/error "Directory '%%$dir$' is not empty!" endif
This script:
- 🔍 Checks if the directory is empty
- ❓ Asks for user confirmation
- 🗑️ Deletes the directory only if confirmed
- ⚠️ Shows an error message if directory is not empty
🖥️ Platform-Specific Notes: iSeries
When working with iSeries systems, there are special considerations:
Without IFS Prefix:
- Libraries can only be deleted if they're not in use
- Libraries must not be on any library list
- Expect negative return values for failures
With IFS Prefix:
- Directories are deleted as expected
- Standard behavior applies
🎯 Best Practices
- Always Check First: Use
$dirlist
to verify directory contents before deletion - Handle Errors: Always check
$procerror
return values - User Confirmation: Implement confirmation dialogs for destructive operations
- Path Validation: Ensure proper directory separator usage
- Authorization: Verify user has sufficient privileges
🔚 Conclusion
The dirdelete
command is a powerful tool for directory management in Uniface. By following proper error handling and validation practices, you can safely implement directory deletion functionality in your applications. Remember to always validate before you delete! 🛡️
Have you used dirdelete
in your Uniface projects? Share your experiences in the comments below! 💬
This article was created with AI assistance and is based on Uniface Documentation 10.4. For more detailed information, refer to the official Uniface documentation.
Top comments (0)