I have the below df:
    JOB_Command Parent_path
0   /data/ingestao_gpdb_nextdm_rep/execucao/call_r...   /data/ingestao_gpdb_nextdm_rep/execucao/call_r...
1   /data/processos/current/ingestao/ciclico/BACEN...   /data/processos/current/ingestao/
2   /data/processos/current/ingestao/ciclico/BACEN...   /data/processos/current/ingestao/
3   /data/processos/current/ingestao/ciclico/BACEN...   /data/processos/current/ingestao/
4   /data/processos/current/ingestao/ciclico/BACEN...   /data/processos/current/ingestao/
5   /data/processos/current/ingestao/ciclico/Inges...   /data/processos/current/ingestao/
And I'm using this piece of code to get the last update of a folder\file.
def get_fourth_elem(file_path):
    """Helper function.
    Args:
        file_path: file path as a string.
    Returns:
        absolute path to the fourth element (or last one if shorter) as a Pathlib object.
    """
    file_path_length = len(file_path.strip("/").split("/"))
    file_path = Path(file_path)
    if file_path_length > 4:
        for _ in range(file_path_length - 4):
            file_path = Path(file_path.parent)
        return file_path
    else:
        return file_path
df_test["Last_Update"] = df_test["JOB_Command"].apply(
    lambda x: datetime.datetime.fromtimestamp(
        get_fourth_elem(x).stat().st_mtime
    ).strftime("%Y-%m-%d %H:%H:%S")
    if Path(x).exists()
    else np.nan
)
But, I'm getting an error when I'm trying to analyze paths that I don't have access, would be possible to treat this and print some form of message "permission denied" ?
here is the sample of the error I'm getting PermissionError: [Errno 13] Permission denied: '/data/processos/current/ingestao/ciclico/IngestionManager_2_0_EXP/sbin/call_ingestion_manager_ciclico_exp.sh'
I tried to add some ifs but, it didn't work, now I'm studying exception, but, couldnt fit yet.
the output shoub be this:
    JOB_Command Parent_path Last_Update
0   /data/ingestao_gpdb_nextdm_rep/execucao/call_r...   /data/ingestao_gpdb_nextdm_rep/execucao/call_r...   2022-09-26 11:30:00
1   /data/processos/current/ingestao/ciclico/BACEN...   /data/processos/current/ingestao/                   2022-09-20 19:20:00             
2   /data/processos/current/ingestao/ciclico/BACEN...   /data/processos/current/ingestao/                   2022-09-20 19:20:00
3   /data/processos/current/ingestao/ciclico/BACEN...   /data/processos/current/ingestao/                   2022-09-20 19:20:00
4   /data/processos/current/ingestao/ciclico/BACEN...   /data/processos/current/ingestao/                   2022-09-20 19:20:00
5   /data/processos/current/ingestao/ciclico/Inges...   /data/processos/current/ingestao/                   NaN
could you gus helpo me?
 
    