Sample Header Ad - 728x90

How to set up local Windows directory in WSL correctly?

-3 votes
1 answer
1722 views
I ran this script in Windows Subsystem for Linux at the command line. I wanted to search for the latest files but I got the error message "no such file or directory", and so I wonder how do I change my script to make it work? Here's my script:
# Set the path to the directory where you want to search for the latest file
directory="C:/Users/nguyen_q/Downloads/Test files/*.csv"

# Get the current date in the format YYYY-MM-DD
echo CURRENT_DATE=$(date +%Y%m%d) 

# Set the variable to hold the name of the latest file
latest_file="" 

# Find all files in the specified directory whose name starts with "MNSUP"
echo files="$(find "$directory" -maxdepth 1 -name "MNSUP*")" 

# Sort the files by modified time, with the most recently modified file first
echo files="$(ls -t $files)" 

# Set the first file in the list as the latest file
echo latest_file="$(echo "$files" | head -n 1)" 

# Check if the latest file contains the current date in the file name
if [[ "$latest_file" == *"$CURRENT_DATE"*.csv ]]; then
  # Print a message if the latest file matches the current date
   echo "$latest_file TODAYYYYY."

else
  # Print a message if the latest file does not match the current date
  echo "$latest_file"

  # Send an email to the user
  echo "The latest file is not present and was not sent to MN.Please re run the job" | mail -s "Latest File Error" "$anna.nguyen@companyname.com"    
fi 

# Print the latest file
# echo "The latest file currently in the folder is: $latest_file"
Asked by Anna Nguyen (21 rep)
Jan 5, 2023, 09:13 PM
Last activity: Jan 7, 2023, 05:04 PM