Ok, so I'm still pretty new to the batch script, and I have this problem with my code, that I use setlocal enabledelayedexpansion in my code for the for loop, the For loop goes through the folder names in a specific directory, but the problem is that some of the names may include "!" (exclamation points), and if so, they are not counted in "! filename!". and when the code creates a new directory, it does not include "!". Also, when xcopy tries to copy files from the source folder, the folder was not found, because the variable "! Filename!" does not match the original (does not have an exclamation mark).
So, I found that for this I only need to add "setlocal enable delayed expansion" to some parts of the code and disable it on the other, but I can not find the right places.
The code:
@ECHO OFF
setlocal enabledelayedexpansion
SET Location_Folder=V:
SET Destination_folder=V:\Nonimportable
SET Check_file_validation=V:\Nonimportable\result.txt
SET Excluded_folder=Nonimportable
set "lineNr=12"
For /f "tokens=*" %%O in ('dir /b /a:d "%Location_Folder%"') do (
set filename=%%O
call D:\somefolder\otherfolder\batscriptname.bat !filename!
set Validation=
echo !filename!| FINDSTR /i /c:"%Excluded_folder%" >NUL
IF ERRORLEVEL 1 (
for /F "skip=12 delims=" %%a in (%Check_file_validation%) do if not defined Validation (
set Validation=%%a
call :valid
)
) else (
echo This folder name is excluded: !filename!
)
)
goto Finish
:valid
echo !Validation!| FINDSTR /c:"1" >NUL
if ERRORLEVEL 1 (
set Folder_path=%Location_Folder%\!filename!
set New_Folder_path=%Destination_folder%\!filename!
mkdir "!New_Folder_path!"
echo D | xcopy /o /y /q /s /v "!Folder_path!" "!New_Folder_path!"
rmdir /s /q "!Folder_path!"
) else (
echo Folder is valid !filename!
goto Finish
)
:Finish
exit /b
Part of the call causes another small (~ 5 lines) batch file that the sqlplus server checks if "! Filename!" really
EDIT: All code works fine and does what it should, if not! in the name of a folder.
source
share