Question

Loop through directory in a batch file


Badge +8

Hello,

 

I created a batch file and need to run it through a task schedular. The file gdb needs to change in this batch file on every run. I am not sure if is there a way to loop through a folder and select the current gdb from the folder.

 

"C:\\Program Files\\FME\\fme.exe" "D:\\Workspace_features\\Country_NEW_APM updates_FeaturesOnly.fmw" TRANSACTION_TYPE_GEODATABASE_SDE "VERSIONING" VERSION_GEODATABASE_SDE "DBO.SarahS_APM_edits_Country_006" geodb "G:\\APM_DOWNLOADS\\Country\\Country_Bulk_2022-05-01_22-43-59\\Country_Bulk_2022-05-01_22-43-59.gdb"

PAUSE

 

Any advice and suggestion would be greatly appreciated!

 

Thanks,

Sarah


6 replies

Badge +8

Hi @fme_can_do_it​ 

There are a few ways to accomplish this.

One option would be to use the FILEPATH reader and Workspace runner to accomplish this with 2 workspaces. see an example here

 

Badge +8

Hi Rahul,

 

Thank you for reply to my question. Actually i used FILEPATH reader and workspace runner initially to run workspaces and I have to run 10+ in a day, but it still takes time to complete each workspace. I have set wait for job to complete Yes. I was looking for some ways to run the processes fast and in less time.

Badge +8

Do you think Python script would work in this case? Is it possible to create a python script to loop through the directory and select recent gdb from the folder and then we can use this gdb as a source dataset to read in user parameter?

Badge +8

If your workflow allows having the same workspace run separately you should be able to set the Wait for job to complete to NO assuming that there is no file locks or ArcSDE table locks restricting the workflow. 

Just want to mention that there is a restriction on a Desktop license to have only a maximum 8 fme*.exe processes running at a given time on a system.  see documentation here

 

Another option would be command-line see here https://community.safe.com/s/article/batch-processing-method-1-command-line-or-batch-fi 

 

Here is an example of a batch file that you can implement, in this file I am reading file geodatabase from a folder and writing to an ArcSDE instance. 

NOTE: The Destination dataset is not a publish parameter in my workflow as it does require to be unless you want to write to a different ArcSDE Instance. 

This process would be still restricted by a maximum number of consecutive FME processes available to run at any given time, but unlike the FME Workspace runner there is no control 

"C:\Program Files\FME_2021.2\fme.exe" "C:\Temp\Country_NEW_APM updates_FeaturesOnly.fmw" --SourceDataset_GEODATABASE_FILE "C:\Share\Data\File Geodatabase\Cities.gdb"
"C:\Program Files\FME_2021.2\fme.exe" "C:\Temp\Country_NEW_APM updates_FeaturesOnly.fmw" --SourceDataset_GEODATABASE_FILE "C:\Share\Data\File Geodatabase\Provinces.gdb"
"C:\Program Files\FME_2021.2\fme.exe" "C:\Temp\Country_NEW_APM updates_FeaturesOnly.fmw" --SourceDataset_GEODATABASE_FILE "C:\Share\Data\File Geodatabase\Roads.gdb"
"C:\Program Files\FME_2021.2\fme.exe" "C:\Temp\Country_NEW_APM updates_FeaturesOnly.fmw" --SourceDataset_GEODATABASE_FILE "C:\Share\Data\File Geodatabase\Lakes.gdb"
"C:\Program Files\FME_2021.2\fme.exe" "C:\Temp\Country_NEW_APM updates_FeaturesOnly.fmw" --SourceDataset_GEODATABASE_FILE "C:\Share\Data\File Geodatabase\Rivers.gdb"
"C:\Program Files\FME_2021.2\fme.exe" "C:\Temp\Country_NEW_APM updates_FeaturesOnly.fmw" --SourceDataset_GEODATABASE_FILE "C:\Share\Data\File Geodatabase\Drainage.gdb"

 

 

Badge +8

In the first example of Source Dataset Geodatabase file name changes to something like Cities_05_02_2022.gdb for the next day's run. I will have to change this gdb name manually in the batch file each time which i want avoid.

Badge +8

In the first example of Source Dataset Geodatabase file name changes to something like Cities_05_02_2022.gdb for the next day's run. I will have to change this gdb name manually in the batch file each time which i want avoid.

Hi Sarah (@fme_can_do_it​ )

Yes, python is also an option and is most likely going to work.

I do have another article that may work better for you see the topic How to Read and Translate all Feature Classes from Multiple Esri Geodatabases

 

Reply