'Expand code for one csv file to multiple csv files in R

I have written R code for a dataset that works as far as I need it to. My problem is that I want to apply this code not only for one CSV file, but for over 8000 CSV files. How can I do this? I have already tried it with a for loop, however it does not work yet. Does anyone have an idea?

My code so far is as follows:

`library(readr)
library(xts)
library(dplyr)
library(lubridate)
library(tidyverse)
library(hms)
library(padr)
library(tidyr)
setwd("C:/Users/Documents/UNI/")
data <- read.csv("AMZN.csv")

#Transform timestamp and round to lower hour
data <- separate(data = data, col = timestamp, into  = c('Date', 'Time'), sep = ' ')
as_hms(data$Time)
data$Time <- trunc_hms(as_hms(data$Time), 60*60)
data$timestamp <- paste(data$Date,data$Time)
data <- data[!duplicated(data$timestamp), ]

#Add timestamp_matrix und merge with stock
data_2 <- read.csv("timestamp_matrix.csv")
data_2_copy <- data_2
data_3 <- merge(data, data_2, by="timestamp")
data_3[ ,c('Date', 'Time')] <- list(NULL)

#Add missing timestamps and fill up with last timestamp
data_3$timestamp <- as.POSIXct((data_3$timestamp), format = "%Y-%m-%d %H:%M:%S")
data_3 <- data_3 %>% pad %>% fill_by_value(users_holding)

    data_3 <- data_3 %>%

 
  

    dplyr::mutate(users_holding = ifelse(users_holding == 0, NA, users_holding)) %>% 
      tidyr::fill(users_holding, .direction = ("down"))

`
r


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source