Hello, I`ve created a batch file where the user can drag and drop a cad file onto it, and it will be translated in to a 3Dpdf.
All of this will be done with a batch file in combination other text files.
But the 3Dpdf translator can also attach other files to (into) the 3Dpdf.
So I intend that the user can drag and drop multiple files on the batch file.
And then I have to search through %1 until however many files where dragged (?).
Firstly I have to find the file with an *.prt extension to define which cad file should be translated (files seem to be ordered alphabetically) and set a variable (e.g. CAD_FILE).
Two files with the *.prt extension are not allowed so I have to give an error if two cad files (*.prt extension) are dragged onto the batch file.
All other files have to be written in to an attachments.txt file with a line break after each file.
I have tried many things but I cannot find a working solution.
I`m thankful for any help or Advice.
Br
Search through command line arguments.
Moderator: DosItHelp
Re: Search through command line arguments.
This piece of code should meet your requirements:
Steffen
Code: Select all
@echo off &setlocal
if "%~1"=="" exit /b
set /a "prt=0, other=0"
>"attachments.txt" (
for %%i in (%*) do (
if /i "%%~xi"==".prt" (
set "CAD_FILE=%%~i"
set /a "prt+=1"
) else (
set /a "other+=1"
echo %%i
)
)
)
if %prt% neq 1 (
del "attachments.txt"
echo ERROR exactly one file with extension .prt required
pause
exit /b
)
if %other%==0 del "attachments.txt"
echo prt file: "%CAD_FILE%"
echo %other% files in "attachments.txt"
pause
Re: Search through command line arguments.
Hello Steffen,
that`s exactly what I needed.
I still have a lot to learn with batch files.
Thank you very much.
that`s exactly what I needed.
I still have a lot to learn with batch files.
Thank you very much.