Tuesday 27 February 2018

Python: Get Filename and Folder Name

Filename


# Get the full name of the input DWG file
s1 = FME_MacroValues['InputDWG']

# If there is a backslash, take the bit after the last one
if "\\" in s1:
    s2 = s1.split('\\')[-1]

# if the output file is in the same folder as the workbench,
# FME uses a relative folder without slashes: $(FME_MF_DIR)foo.bar
elif "FME_MF_DIR" in s1:
    s2 = s1[13:]

# Chop off the extension
return s2.split('.')[0]


Folder Name


import os

# Get the full name of the first input DWG file
s1 = FME_MacroValues['InputDWG']

# If there is a backslash, take the folder name
if "\\" in s1:
    s2 = os.path.dirname(s1)

# if the output file is in the same folder as the workbench,
# FME uses a relative folder without slashes: $(FME_MF_DIR)foo.bar
elif "FME_MF_DIR" in s1:
    s2 = FME_MacroValues['FME_MF_DIR']

return s2

No comments:

Post a Comment

Combine Raster Bands

To combine multiple single-band rasters into a single multi-band raster, use the RasterBandCombiner transformer. For example, combine the ...