I'm new to this forum but I thank in advance anyone help me ..
I am writing to ask for help ... I need to create a .Bat file that performs the following tasks:
If in the folder there is only .txt files I have to play the first "IF" if there are more than one then I have to play the second.
If there are “zero” files (no file) do not have to do anything.
The program inside the first “IF” if taken individually works, but I Can not set the condition of 'IF and the condition to end.
Someone can help me?
Thanks in advance
Code: Select all
@echo off
REM enter into directory
@CD %c:\Test%
REM count the .txt file present
set cnt=0
for %%A in (*.txt) do set /a cnt+=1
echo File count = %cnt%
REM if the number is equal to "1" run of operations. If it is different from "1" move all the files to another directory
IF %cnt% == 1 end
(
FOR %%i IN (*.txt)DO SET var=%%i
REM if there is at least one file with extension .txt
IF %var%== GOTO end
REM creo una nuova variabile per eseguire un "Substring"
SET nuovovar=%var:~2,-4%
REM e tramite essa creo i nuovi files
COPY NUL CUST_%nuovovar%.dat
COPY NUL INVN_%nuovovar%.dat
COPY NUL LOG_%nuovovar%.dat
COPY NUL M_%nuovovar%.dat
COPY NUL P_%nuovovar%.dat
COPY NUL PO_%nuovovar%.dat
COPY NUL storeqty_%nuovovar%.dat
COPY NUL VEND_%nuovovar%.dat
REM rename file .txt
REN %var% %var:~0,-4%.dat
REM move file
COPY . %dest%\.
ERASE/Q .
:end
REM activation READY OK
REN %dest%\READYTX READYRX
)
:end
IF NOT %cnt%==1 end2
(
REM enter into the directory where I move all files
@SPOST %c:\Test\Spostati%
REM sposto il contenuto della
REM directory nella sua destinazione definitiva
COPY . %SPOST%\.
ERASE/Q .
)
:end2