I use the below code in order to create a directory from the value of the first 4 chars of collector text file
@echo off & setlocal enabledelayedexpansion
:loop
set /P txt_file=<Collector.txt
Set collector_id=!txt_file:~0,4!
:: check for existence of [OutputFolder]
:: if [OutputFolder] doesn't exist, create it
if not exist %collector_id% (
echo folder %collector_id% not found
echo creating folder %collector_id%
md %collector_id%
)
xcopy *.txt %collector_id% /v
Del *.txt
goto loop
I want to execute the above loop continuously in order to check if current directory is empty or not. If not I want to make a dir, if does not exist, with name the first 4 chars of collector.txt.
If the directory is not empty everything is ok. When the above is looping and I add collector.txt to the current directory the collector_id does not change.
Where am I wrong?
Is there any other way, expect infinite, loop to do this?
Put setlocal EnableDelayedExpansion
at the start, and use !var!
instead of %var%
. Then it is evaluated every time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With