@takashi
Greetings FME sensei, good to see you're still around! I had a question about a Python script I'm using as a Private Parameter linked to two published parameters to generate log file folders that include the local user and date in the folder name, then generates time/date stamped log files within those folders.
Here's the script:
# Scripted (Python) Parameter Example
# Create log file path with time stamp.
import fme, time, os
d = FME_MacroValues['Log_File_Dir'] # directory path
w = FME_MacroValues['User_Name'] # workspace name
t = time.strftime('%Y%m%d%H%M%S') # time stamp
f = FME_MacroValues['Folder_Name_Date'] # date in folder name
# If the workspace name ends with ".fmw", remove it.
if w.endswith('.fmw'):
w = w[:-4]
# Create a new folder which has the name of the workspace.
dir = os.path.join(d, w, f)
if not os.path.exists(dir):
os.mkdir(dir)
# If the expected path conflicts with an existing file,
# append sequential number to avoid overwriting it.
base = os.path.join(dir, t)
path = '%s.log' % base
n = 1
while os.path.exists(path):
path = '%s_%d.log' % (base, n)
n += 1
return path
When I run the workbench with the text in bold set to the built-in FME_MF_DIR parameter, it runs correctly, but when I run it as above, it fails without returning any error notifications. What am I doing wrong?
The path defined by the "Log_File_Dir" parameter is a UNC network path. I tried a few combinations of the forward and backward slashes as indicated in prior posts, but to no avail.