-1
@ECHO OFF

call:genname build_logs/FRAS
set fras_logname=%newname%.log

python setup.py build >> %fras_logname%

:::::::::::::::::: FUNCTION ::::::::::::::::::::::::
:genname
    set d1=%date:~-4,4%
    set d2=%date:~-10,2%
    set d3=%date:~-7,2%
    set t1=%time:~0,2%
    ::if "%t1:~0,1%" equ " " set t1=0%t1:~1,1%
    set t1=%t1: =0%
    set t2=%time:~3,2%
    set t3=%time:~6,2%
    set filename=%~1
    set newname=%filename%_%d1%%d2%%d3%_%t1%%t2%%t3%

I am trying to figure out what this batch file does? I am thinking it creates a log file with date and time but when I try to run this it gives this The system cannot find the path specified. Kindly help!

  • 1
    it's a very bad script. `%date%` changes output depending on locale settings, so never use it. Use [wmic instead](https://stackoverflow.com/q/56165593/995714) – phuclv Nov 03 '22 at 07:46
  • Like phuclv said, it depends on locale, but _theoretically_ it appends the date and time in the format YYYYMMDD_HHMMSS to the filename. Interestingly, `>>` will create a new file if one does not exist already, so I think you're getting that error because `setup.py` doesn't exist (or you aren't where you think you are). – SomethingDark Nov 03 '22 at 07:47
  • You are correct in your conclusion. The problem with your script appears to be that you have a forward slash in your directoryname and you require a backslash. – Magoo Nov 03 '22 at 07:49
  • @phuclv so I should change ```set %date%``` to instead``` set wmic os get LocalDateTime /VALUE```? I haven't written this script, I am just told to work on this without documentation :// – Abhinandan Nov 03 '22 at 08:39
  • @SomethingDark I understood it's running the command ```python setup.by build >>``` and creating a build log also setup.py is my directory I tried to run to it directly that worked but I was wondering if I should do it using this script because I was told to use this instead. – Abhinandan Nov 03 '22 at 08:40
  • @Magoo where? in the line ```call:genname build_logs/FRAS``` ? – Abhinandan Nov 03 '22 at 08:47
  • @SomethingDark should I run it like this ```./build.bat ``` – Abhinandan Nov 03 '22 at 08:54
  • Is there another forward slash in your posted code? – Magoo Nov 03 '22 at 10:05
  • There should be placed the line `goto :EOF` before the function/sun-routine in order not to fall into it again after the Python command line… – aschipfl Nov 03 '22 at 22:22

1 Answers1

1

You should try like this way :


@ECHO OFF
Set "FRAS_Folder=%~dp0build_logs\FRAS"
If Not Exist "%FRAS_Folder%" MD "%FRAS_Folder%"
Call :Gen_Report_Name fras_logname
echo FileName : "%fras_logname%"
echo Absolute PathName : "%FRAS_Folder%\%fras_logname%"
REM Example save the result of this command with a log file into this folder
ipconfig /all > "%FRAS_Folder%\%fras_logname%"
pause & exit /b

:::::::::::::::::: FUNCTION :::::::::::::::::::
:Gen_Report_Name <file_with_date to be set>
for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set "dt=%%a"
set datestamp=%dt:~0,8%
set timestamp=%dt:~8,6%
set YYYY=%dt:~0,4%
set MM=%dt:~4,2%
set DD=%dt:~6,2%
set HH=%dt:~8,2%
set Min=%dt:~10,2%
set Sec=%dt:~12,2%
set "stamp=%YYYY%%MM%%DD%_%HH%%Min%%Sec%"
Set "%1=%stamp%.log"
Exit /b
::------------------------------------------------------------------------------------
Hackoo
  • 18,337
  • 3
  • 40
  • 70
  • Thanks @hackoo it's working and creating a build log which has all my computer specs, I just have one question where do I add ```python setup.py build``` line, does it go in after ```REM...``` – Abhinandan Nov 03 '22 at 08:51
  • @Abhinandan yep just replace `ipconfig /all >"%FRAS_Folder%\%fras_logname%"` by your command `python setup.py build>"%FRAS_Folder%\%fras_logname%"` – Hackoo Nov 03 '22 at 09:19