Path management

Tool
R
Python
Author

Tony D

Published

March 27, 2025

Since windows and mac have different file path, we use package to manage the file path.

fs pacakge

Code
#pak::pkg_install('here')
#pak::pkg_install('fs')
library(fs)
Code
getwd()

list file in the current directory

Code
dir_ls()

create a new directory

Code
# create a new directory
tmp <- dir_create(file_temp())
tmp

create new files in that directory

Code
# create new files in that directory
file_create(path(tmp, "my-file.txt"))
dir_ls(tmp)

remove files from the directory

Code
# remove files from the directory
file_delete(path(tmp, "my-file.txt"))
dir_ls(tmp)

remove the directory

Code
# remove the directory
dir_delete(tmp)

here package

Code
library(here)

show project directory

Code
here()

show all file in the project directory

Code
list.files(here())

show one file path

here.png in images folder

Code
image_path=here('posts/path_managment/images','here.png')
image_path