Skip to main content

Hello,

I am looking for additional insights on File Copy

  • Is it possible to copy folder structure without copying files inside ? How do I set the writer ?
  • What is the filecopy_type parameter ? and what are it’s possible values ? The parameter exists on the writer but I can’t find any information.

Thank you

 

Hi ​@tsirkuse ,

I don't think that there is any option to copy only folder structure with File Copy writer unfortunately.

However, Python scripting might help you. For example, this script defined in a PythonCaller creates the same folder structure as the subfolders of “_source_folder” under “_destination_folder”.

import fme
import fmeobjects, os

class DirectoryCopier(object):
def __init__(self):
pass

def input(self, feature: fmeobjects.FMEFeature):
def copy_dirs(src, dst):
with os.scandir(src) as iter:
for entry in iter:
if os.path.isdir(entry.path):
dir = os.path.join(dst, entry.name)
os.makedirs(dir)
copy_dirs(entry.path, dir)

src = feature.getAttribute('_source_folder')
dst = feature.getAttribute('_destination_folder')
copy_dirs(src, dst)
self.pyoutput(feature)

def has_support_for(self, support_type: int):
return support_type == fmeobjects.FME_SUPPORT_FEATURE_TABLE_SHIM

def process_group(self):
pass

def close(self):
pass

 


You could use the Directory and File Pathnames reader to read only the folders, then write a blank text file to the lowest folders (to create all the higher folders in the tree), then go through a delete the blank text files.

In my view, ​the approach @takashi outlined would be what I’d choose unless overarching policies blocked the use of Python


You can also use SystemCaller, and invoke xcopy (of robocopy) there.
With xcopy use something like

xcopy "c:\temp\MyOriginalFolder\" "c:\temp\MyCopyFolder\" /t/e

Use /t to copy only the folder structure, not the files
Use /e to include empty folders

 


Reply