I wanted to remove the last forward slash of a directory string so that I use the same path for forfiles tool to delete old files. I have tried the solution here but it didn't work. The script saves the output to a text file so that I see the result. The forfiles doesn't work as the directory is incorrect format.
What I want to just to remove the last backward slash "C:\Database\Backup\"
.
The runable code below is what I have attempted. The problem is line 6, which outputs "C:\Database\Backup\" :~0,-1
instead of "C:\Database\Backup"
set BACKUP_DIR="C:/Database/Backup/"
set LOG_FILE=%BACKUP_DIR%log_file.txt
if not exist BACKUP_DIR mkdir %BACKUP_DIR%
set BACKWARD_SLASH_DIR=%BACKUP_DIR:/=\%
echo %BACKWARD_SLASH_DIR% > %LOG_FILE%
set DELETE_DIR=%BACKWARD_SLASH_DIR%:~0,-1%
echo %DELETE_DIR% >> %LOG_FILE%
forfiles -p %DELETE_DIR% -s -m *.* -d -1 -c "cmd /c echo Deleted @file" >> %LOG_FILE%
forfiles -p %DELETE_DIR% -s -m *.* -d -1 -c "cmd /c del @path"