Creating a Unique File Name

If you are working with files or file attachments in PeopleCode, you will typically want to create a unique file name for each user to prevent them from overwriting each others files if files are being stored in the same folder.

Here's a simple piece of PeopleCode that generates a file name prefix with the format OPRID-Date-Time. Note that the date and time formats will be specific to your region.

Local string &sFilePrefix; &sFilePrefix = %OperatorId | , ) | "-";

The Substring(String(%Time), 1, 8) drops the millisecond component of the time stamp (which is 6 digits long). If you want to include the millisecond component, don't perform the Substring. Note also that %Time is the database time not the application server time. If you want the application server time use %PerfTime instead. The application server time %PerfTime might be more accurate for file attachments for example.

If you have a number of files per each user, you might want to consider creating a subdirectory for each each operator ID and placing files in there.

Note that the reason for using Operator IDs is that they have a strict format and don't contain any spaces.

This isn't the case for run control IDs. For example you can create run control IDs like these:

  • try saving this \/:*?"<>|
  • rm -r -f /

Not the most ideal file names! That is why run control ID is not used in the file prefix.

上一篇:[PHP学习教程 - 文件]002.判断远程文件是否存在(Remote File Exists)


下一篇:judge remote file exist