Skip to main content

Does any one know how to read the latest file from a One Drive folder. I'm able to select a file from the One Drive folder using a Microsoft OneDrive (Graph) web connection, but I can't find a way to read all the files in the folder and then find the latest. I have read the question regarding reading the newest file for a folder https://knowledge.safe.com/questions/65203/read-only-the-newest-file-from-a-directory.html. It's very helpful condeptually. I would appreciate an thoughts or insight.

 

Thanks,

Frank

Hi @billybob,

I believe you will want to use two OneDriveConnector transformers - one will list the folder contents and the other will download the latest file.

The first OneDriveConnector should be set to the list action for a folder. This will provide you with attributes holding information about the file including the last modified date. You can then set up a filter to ensure you are only getting the latest file.

From there, you should be able to use the attribute that holds the file ID in a second OneDriveConenctor that is set to the download action.

- Andrea


Hi @billybob,

I believe you will want to use two OneDriveConnector transformers - one will list the folder contents and the other will download the latest file.

The first OneDriveConnector should be set to the list action for a folder. This will provide you with attributes holding information about the file including the last modified date. You can then set up a filter to ensure you are only getting the latest file.

From there, you should be able to use the attribute that holds the file ID in a second OneDriveConenctor that is set to the download action.

- Andrea

Hi @andreaatsafe

Thanks, that works. Do you know if there is a way to read the file (latest) directly from OneDrive versus having to download it? We have used the Microsoft OneDrive (Graph) web connection to select a excel file in a OneDrive folder to read, but we like to be able to locate a file (latest in my example) and then select the file and read it without having to download it first. Is that possible?

Thanks,

Frank


Hi @andreaatsafe

Thanks, that works. Do you know if there is a way to read the file (latest) directly from OneDrive versus having to download it? We have used the Microsoft OneDrive (Graph) web connection to select a excel file in a OneDrive folder to read, but we like to be able to locate a file (latest in my example) and then select the file and read it without having to download it first. Is that possible?

Thanks,

Frank

I'm trying the use a FeatureReader connected to the OneDriveConnector, but I can't get the dataset value assigned. I tried using the path and the "_name" attribute from the OneDriveConnector, but that doesn't work. I'm sure there is a way to do this, but I'm not having any luck figuring it out.


I'm trying the use a FeatureReader connected to the OneDriveConnector, but I can't get the dataset value assigned. I tried using the path and the "_name" attribute from the OneDriveConnector, but that doesn't work. I'm sure there is a way to do this, but I'm not having any luck figuring it out.

If you're wanting the workflow to be dynamic to always pull the latest file, you will need to use a workflow to list the contents, filter and then download the appropriate (latest) file.

For reading the file after downloading, you'll need to build the path for the dataset in the FeatureReader.

To do this, I would suggest creating a publish parameter to hold the folder to download the file to (You can do this by using the dropdown next to "Download to Folder" > User Parameter > Create User Parameter...):

 

Then in the FeatureReader you can build the path with the published parameter and the attribute holding the name of the file, using the Text Editor:

 


If you're wanting the workflow to be dynamic to always pull the latest file, you will need to use a workflow to list the contents, filter and then download the appropriate (latest) file.

For reading the file after downloading, you'll need to build the path for the dataset in the FeatureReader.

To do this, I would suggest creating a publish parameter to hold the folder to download the file to (You can do this by using the dropdown next to "Download to Folder" > User Parameter > Create User Parameter...):

 

Then in the FeatureReader you can build the path with the published parameter and the attribute holding the name of the file, using the Text Editor:

 

Hi Andrea,

Great idea. The problem now is that the FeatureReader doesn't read the dataset. When i select the "Parameters..." button, there is "no dataset", thus the excel sheet isn't available. Any thoughts on this?

Thanks,

Frank


Hi Andrea,

Great idea. The problem now is that the FeatureReader doesn't read the dataset. When i select the "Parameters..." button, there is "no dataset", thus the excel sheet isn't available. Any thoughts on this?

Thanks,

Frank

This is expected when setting the dataset to parameter and/or attribute values. The dataset location is not known until the FME workspace is run.

 

If you are needing to set certain parameters and set up how the excel file should be read in (if the default is not okay), then I would recommend pointing the dataset to an actual file and set the parameter accordingly. If all your Excel files have the same schema set up, be sure to set the "Multiple File Handling" parameter to "Use Current Settings" so that all further Excel files will be read with the same settings. Then change the dataset location to the parameter + attribute set up you have (do not open the parameters up again as the settings may reset).

If the default settings are okay, then you should not need to worry about this and you will see features being read out the Generic port.

To understand and learn more about the FeatureReader, I'd recommend reviewing this article and the child articles just to see how the transformer can work too.


Hi Andrea,

I've been trying to accomplish basically everything described in this article. I've used 2 OneDrive connectors, am able to run the workbench on my pc no issues, even outputting the results to a feature writer. My issue is trying to publish the workbench to FME Flow (still using 2022.0 version on my desktop and server). The workbench publishes no problems, but when I try to run it on the server the job appears to open and read the correct .CSV file but halfway through I get an error message:

CSV reader:

Failed to open file 'C:/Users/Mylocation/OneDrive - myCompany.com/MyFolder/HB_metadata_250923.csv' for reading. Please ensure that the file exists and you have sufficient privileges to read it.

There shouldn't be any reason for not having sufficient permissions since I'm logged in and authenticated to the One Drive folder, and I have uploaded my credentials to server along with the workbench.

Any thoughts?

Thanks

Chad

 


Reply