Greetings fellow mortals! I will cut right through it.
What I am trying to achieve & how it works
I am currently trying to create a simple batch-script which iterates through files in a source directory, validates the file extension and count the file size of each file with the right extension, which in this case is .xml
.
Upon checking for these conditions, the files will be moved to their respective directory.
What I've tried so far
While doing the first condition of checking the file extension, my logic seems to be flawed. (explained after the code block.)
I am not used to creating scripts in batch
and therefore not entirely used to the syntax - but I hope it's correct!
I've kept the echo
's as a debug reference for the output later in this post.
@ECHO OFF
SETLOCAL
SET "sourcedir=C:\lorem\ipsum"
SET "destdir=C:\foo\bar"
FOR %%G IN ("%sourcedir%\*") DO (
IF NOT "%%~nxG"=="*.xml" (
echo %%~nxG
::echo (MOVE "%%G" "%destdir%\not-accepted")
echo "move file to \not-accepted"
) ELSE (
FOR %%i in ("%sourcedir%\*.xml") DO (
@set count=%%~zi
echo "%count%"
IF "%count%" LEQ 200 (
echo "move file to \empty-pba"
) ELSE (
echo "move file to \import"
)
)
)
)
pause
The first statement never seem to give a false condition, despite having file extensions that doesn't match the condition and therefore does not continue to the next for-loop, meaning the allowed file extension is always moved to the \not-accepted folder.
The output is as follows:
lorem.xml
"move to \not-accepted"
foo.pdf
"move to \not-accepted"
ipsum.xml
"move to \not-accepted"
bar.pdf
"move to \not-accepted"
My initial question
Is my logic flawed here? My first bet is that I've probably messed up the if
-statement somehow, either syntax error or that I've completely missed on the logic here. Am I doing something illegal?
The time you've already spent reading this and the help is already greatly appreciated! <3