Вопрос

I'm working that will unzip an archive and will open a file with a certain extension. The issue that I have is that I don't know how to store the name of the file and after that to open it. The file isn't in the root directory , it is in a folder that has a dynamic name and this folder is placed in root directory In order to find the file I can use dir/s *.rte , but after that I don't know how to store the name of the file. Here is what I written until now.

        echo on
::get the name of the .bat file
set folder_name=%~nx0
::replace string _open.bat with blanks
set folder_name=%folder_name:_open.bat=%
::set report directory
set reportdir=%folder_name%
::set report file
::This should be dynamic not hard codded 
set reportfile=TransmissionRatio\RTE_px_TransmissionRatio_LAST_RESULTS.rte
::remove  report directory
rmdir /s/q %reportdir% 
::unpack archive
..\..\..\..\PrjTstTools\zip\7za x %reportdir%.zip -o%reportdir%
cd %reportdir%
::open report file
explorer %reportfile%
pause

Best regards

Это было полезно?

Решение

This will remember the last .rte file in the folder.

for %%a in (*.rte) do set "filename=%%a"
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top