DEV Community

Peter + AI
Peter + AI

Posted on

Mastering Directory Renaming in Uniface 10.4: The dirrename Command πŸ“

Hey fellow developers! πŸ‘‹ Today we're diving into one of Uniface's handy ProcScript commands that makes directory management a breeze: dirrename. Whether you're organizing your project structure or managing dynamic file operations, this command is your friend! ✨

What is dirrename? πŸ€”

The dirrename statement is Uniface's built-in solution for renaming directories programmatically. It's clean, simple, and handles all the platform-specific details for you.

Basic Syntax πŸ“

dirrename DirPath, NewDirName
Enter fullscreen mode Exit fullscreen mode

Quick Example πŸš€

dirrename "data/exports", "saved"
Enter fullscreen mode Exit fullscreen mode

That's it! Your "exports" directory inside "data" is now called "saved". Pretty straightforward, right? 😊

Parameters Breakdown πŸ“‹

Parameter Data Type Description
DirPath String Directory name with optional path. Can even be in a zip archive! πŸ“¦
NewDirName String New directory name. Keep it simple - no path separators at the end! ⚠️

Return Values & Error Handling πŸ›‘οΈ

Always check your $procerror value:

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

Pro Tips & Best Practices πŸ’‘

Path Separators

Uniface is smart about separators! You can use:

  • Forward slash: /
  • Backward slash: \
  • Bracket notation: [a.b]

Different Ways to Rename

// Standard approach
dirrename "drinks/coffee/", "tea"

// Bracket notation (my personal favorite! πŸ˜„)
dirrename "[drinks.coffee]", "tea"

// Using $RES (resources path)
dirrename "$RES:drinks/coffee", "tea"
Enter fullscreen mode Exit fullscreen mode

When Things Go Wrong 🚨

The operation will fail if:

Source Directory Issues:

  • Directory doesn't exist 🚫
  • Not actually a directory
  • Directory is not empty
  • Directory is locked/in use πŸ”’
  • Insufficient permissions

Target Name Issues:

  • Name already exists πŸ”„
  • Invalid syntax
  • Trying to use $RES as target

Special Considerations 🎯

iSeries Users

Library renaming has special rules - libraries must not be in use or on someone else's library list. Always be prepared for negative return values! πŸ“Š

Path Limitations

Keep your paths under 255 bytes total length. Modern systems shouldn't have issues, but it's good to know! πŸ“

Real-World Example 🌍

// Let's organize our backup directories
if ($procerror = 0)
    dirrename "backup/temp", "backup_" + $date
    if ($procerror != 0)
        message "Failed to rename backup directory!"
    endif
endif
Enter fullscreen mode Exit fullscreen mode

Wrapping Up 🎁

The dirrename command is a powerful yet simple tool in your Uniface toolkit. It handles cross-platform compatibility gracefully and integrates seamlessly with Uniface's file system abstractions.

Remember to always check your error codes, and don't forget about those path length limitations! Happy coding! πŸš€


Found this helpful? Drop a πŸ’– and let me know in the comments! Got questions about other Uniface commands? I'd love to help!

πŸ“š Based on Uniface Documentation 10.4 | Created with AI assistance

Top comments (0)