esd ---> iso script (Testing in progress)

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

Re: esd ---> iso script (Testing in progress)

#76 Post by balubeto » 31 Oct 2016 10:58

Squashman wrote:
balubeto wrote:
Excuse me but I can not understand how it is the correct full script.

Thanks

Bye

What do you not understand about fixing problems 1 and 2? That is basic syntax that you should already understand.


I tried to do all the fixes on the script not working but still does not work. Why?

Excuse me again.

Thanks

Bye

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: esd ---> iso script (Testing in progress)

#77 Post by penpen » 01 Nov 2016 09:07

balubeto wrote:Excuse me but I can not understand how it is the correct full script.
What exactly is unclear to you?

balubeto wrote:I tried to do all the fixes on the script not working but still does not work. Why?
Without seeing your latest code, it is hard to give a proper answer to this question.


penpen

balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

Re: esd ---> iso script (Testing in progress)

#78 Post by balubeto » 01 Nov 2016 10:39

penpen wrote:
balubeto wrote:Excuse me but I can not understand how it is the correct full script.
What exactly is unclear to you?

balubeto wrote:I tried to do all the fixes on the script not working but still does not work. Why?
Without seeing your latest code, it is hard to give a proper answer to this question.


penpen


I tried to correct the errors that you found but I'm not sure if I understood right.

Here is my current script:

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion

call :setValidPath    "Windows_Files_Path" "%~1" "Enter the directory in which put the content of the 'Windows Setup Media' volume image:"   "absolutePath" "mayExist"   "directory"  "rw"
call :setValidPath    "iso_Path"           "%~2" "Enter the directory in which put the iso image file created:"                              "absolutePath" "mayExist"   "directory"  "--"
call :setValidPath    "esd_Path"           "%~3" "Enter the directory in which put the esd unencrypted file:"                                "absolutePath" "mustExist"  "directory"  "--"
call :setValidPath    "esd_File"           "%~4" "Enter the file to be converted which should be put in the %esd_Path% directory:"           "relativePath" "mustExist"  "file"       "rw" "esd_Path"
call :IsoFile         "%iso_Path%"         "%~2"  "%~3"                                                                                      "%~4"
call :ValidTimestamp  "Timestamp"          "%~5" "Enter a timestamp ('mm/dd/yyyy,hh:mm:ss') for all files and directories in the %iso_File%:"

echo(
echo Result:
echo Windows_Files_Path: "%Windows_Files_Path%"
echo iso_Path          : "%iso_Path%"
echo esd_Path          : "%esd_Path%"
echo esd_File          : "%esd_File%"
echo iso_File          : "%iso_File%"
echo iso_Volume_Label  : "%iso_Volume_Label%"
echo timestamp         : "%timestamp%"

:: put your code here

endlocal
goto :eof


:setValidPath
:: %~1   variable to set
:: %~2   default value
:: %~3   text if default value is invalid
:: %~4   Text equals: (forced to relativePath if %~6 equals file)
::     absolutePath  if path must be absolute
::     relativePath  if path must be relative
::     anyPath       if path may be relative or absolute (any other value)
:: %~5   Text equals: (forced to mayExist if %~8 does not exist)
::     mustExist     if file/directory must exist,
::     doesntExist   if file/directory is not allowed to exist.
::     mayExist      if file/directory may or may not exist (any other value).
:: %~6   Text equals:
::     file          if object to test is a file
::     directory     if object to test is a directory (any other value).
:: %~7   Text equals: (only checked if file/directory exists)
::     r             check read access for specified file/directory
::     w             check write access for specified file/directory
::     rw            check read and write access for specified file/directory
::     -             check no access for specified file/directory (any other value)
::     directory     if object to test is a directory (any other value).
::     Note: testing write access on a directory creates a file "test.tmp"
:: %~8   Only if /I %~6 == "file": environment variable with an path to store the file to
::   (forced to empty word, if %~6 equals directory).
::
 
   setlocal
   set "firstTime=1"
   set "input=%~2"
   set "text=%~3"
   if        "%~4" == "absolutePath" ( set "pathType=%~4"
   ) else if "%~4" == "relativePath" ( set "pathType=%~4"
   ) else set "existType=anyPath"
   if        "%~5" == "mustExist" ( set "existType=%~5"
   ) else if "%~5" == "doesntExist" ( set "existType=%~5"
   ) else set "existType=mayExist"
   setlocal enableDelayedExpansion
   set "parent= "
   if "%~6" == "file" (
      set "parent= !%~8!"
      if not "!parent:~-1!" == ":" (
         set "parent=!parent!\"
         if "!parent:~-2!" == "\\" set "parent=!parent:~0,-1!"
      )
   )
   endlocal & set "parent=%parent:~1%"
   if "%~6" == "file" (
      set "fileType=file"
      set "pathType=relativePath"
      if defined parent (
         if not exist "%parent%" set "existType=mayExist"
      ) else set "existType=mayExist"
   ) else set "fileType=directory"
   if        "%~7" == "r"  ( set "checkAccess=r-"
   ) else if "%~7" == "w"  ( set "checkAccess=-w"
   ) else if "%~7" == "rw" ( set "checkAccess=rw"
   ) else                  ( set "checkAccess=--"
   )

:validatePath
   :: validating
   set "invalid="
   call :isValidPathName "input" || goto :invalidatedPath
   if        /I     "%pathType%" == "absolutePath" ( call :isAbsolutePathName "input" || ( set "invalid=Path must be absolute" & goto :invalidatedPath )
   ) else if /I     "%pathType%" == "relativePath" ( call :isAbsolutePathName "input" && ( set "invalid=Path must be relative" & goto :invalidatedPath ) || >&2 >nul
   )
   setlocal enableExtensions enableDelayedExpansion
   set "input=!parent!!input!"
   if        /I     "%existType%" == "mustExist"   ( if not exist "!input!" ( endlocal & set "invalid=Path must exist." & goto :invalidatedPath           )
   ) else if /I     "%existType%" == "doesntExist" ( if     exist "!input!" ( endlocal & set "invalid=Path must be non existent." & goto :invalidatedPath )
   )

   if exist "!input!" for %%b in ("!input!") do (
      set "attribs=%%~ab"
      if /I "%fileType%" == "file" (
         if not "!attribs:d=!" == "!attribs!" (
            endlocal & set "invalid=Path must denote a file (not a directory)." & goto :invalidatedPath
         ) else (
            if "%checkAccess:~0,1%" == "r" (
               2>nul <"!input!" set /p "check=" || (
                  for %%a in ("!input!") do if "%%~za" == "0" (
                     >&2 echo(Warning: Could not verify read access: Reason filesize of "!input!" is 0.
                  ) else (
                     endlocal & set "invalid=No read access (wanted)." & goto :invalidatedPath
                  )
               )
            ) else if "%checkAccess:~1,1%" == "w" 2>nul (
               >"!input!" <nul set /p "check=" || ( endlocal & set "invalid=No write access (wanted)." & goto :invalidatedPath )
            )
         )
      ) else (
         if "!attribs:d=!" == "!attribs!" (
            endlocal & set "invalid=Path must denote a directory (not a file)." & goto :invalidatedPath
         ) else (
            if "%checkAccess:~0,1%" == "r" 2>nul (
               >nul dir "!input!" || ( endlocal & set "invalid=No read access (wanted)." & goto :invalidatedPath )
            )
            if "%checkAccess:~1,1%" == "w" 2>nul (
               >nul pushd "!input!"
               >"test.tmp" echo test || ( >nul popd & endlocal & set "invalid=No write access (wanted)." & goto :invalidatedPath )
               >nul del "test.tmp"   || ( >nul popd & endlocal & set "invalid=No write access (wanted)." & goto :invalidatedPath )
               >nul popd
            )
         )
      )
   )

   endlocal
   endlocal & set "%~1=%input%"
   goto :eof

:invalidatedPath
   if defined invalid echo(Invalid: %invalid%
   set /P ^"input=%text:""="% "
   goto :validatePath
   goto :eof


:: Check if the pathname follows mainly the naming convention:
:: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
:: Exceptions:
::  - Only a drive descriptor (for example "C:") is allowed for volume names.
::  - Not tested if characters 0x00-0x31, or any other forbidden character (of the target filesystem) are present. (disallowed)
::  - Not tested on alternative data streams
:isValidPathName
:: %~1   environment variable containing the path to test.
   setlocal enableExtensions enableDelayedExpansion
   set "pathName=!%~1!"
   set "invalid="
   if not defined invalid if "!pathName!" == "" if defined firstTime (exit /b 1 & goto :test) else set "invalid=The pathname cannot be empty." & set "pathName= "
   if not defined invalid for /f tokens^=1^*^ delims^=^/^<^>^|^*^?^" %%a in ("#!pathName!#") do if not "%%~b" == "" set "invalid=Invalid character found."
   if not defined invalid set ^"pathname=!pathname:"=!"

   if not defined invalid (
      set "pathName= !pathName:/=\!"
>nul echo @maybe:set "pathName= !pathName:\..\=\!"
>nul echo @maybe:set "pathName= !pathName:\.\=\!"
>nul echo @maybe:if "%pathName:~-3%" == "\.." set "pathName= !pathName:~0,-3!"
>nul echo @maybe:if "%pathName:~-2%" == "\." set "pathName= !pathName:~0,-2!"
   )

   if not defined invalid if not "!pathName:\\=__!" == "!pathname!" set "invalid=Empty string is no valid path component."
   if not defined invalid if "!pathName:~1,1!" == ":" (
      for /f "tokens=1* delims=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" %%a in ("#!pathName:~0,1!#") do if not "%%~a" == "#" set "invalid=Invalid drive name."
      set "pathName=!pathName:~2!"
   )
   if not defined invalid 2>nul (
      echo(\!pathname!\|>nul findstr /I /R /C:"[\\]AUX[\\]" /C:"[\\]CON[\\]" /C:"[\\]NUL[\\]" /C:"[\\]PRN[\\]" /C:"[\\]COM[0-9][\\]" /C:"[\\]LPT[0-9][\\]" && (
      )
   )
   if not defined invalid 2>nul (
      echo(\!pathname!\|>nul findstr /R /C:"[\ ][\\]" /C:"[\.][\\]" && (
         set "invalid=It is not allowed to end file/directory names with a space (' ') or a period ('.') character."
      )
   )
   if not defined invalid (
      endlocal
      exit /b 0
   ) else (
      endlocal & set "invalid=%invalid%"
      exit /b 1
   )
   goto :eof


:: Using mainly the definition of the Windows Shell API, see:
:: https://msdn.microsoft.com/en-us/library/windows/desktop/bb773660(v=vs.85).aspx
:: Exception:
::  - Only accepts a drive descriptor (for example "C:") is allowed for volume names.
::
:: does not check validity (must be valid)

:isAbsolutePathName
:: %~1   environment variable containing the path to test.
   setlocal enableExtensions enableDelayedExpansion
   if not "!%~1:~1,2!" == ":\" (
      endlocal
      exit /b 1
   ) else (
      endlocal
      exit /b 0
   )
   goto :eof

:IsoFile
   call :setValidPath   "iso_File"           "%~2"  "Enter the iso file (in the UDF 1.02 format) that will be saved in the %iso_Path% directory:"  "relativePath" "mayExist"   "file"       "-w" "iso_Path"
   call :isoFileExist   "%~1"                "%~2"
   call :setValidLabel  "iso_Volume_Label"   "%~3"
   call :ValidTimestamp  "Timestamp"         "%~4" "Enter a timestamp ('mm/dd/yyyy,hh:mm:ss') for all files and directories in the %iso_File% : "
   goto :eof

:isoFileExist
   call
   if exist "%~1\%iso_File%" choice /M "Iso File exists; overwrite it? " /C:YN
   if not "%errorlevel%" == "1" (
      if "%errorlevel%" == "0" echo(
      call :IsoFile "%~1" ""
   )
   goto :eof

:ValidTimestamp
:: Caution!
:: This function creates two subdirectories "dummy\empty".
:: Don't use these directories!
:: These directories were deleted automatically.
:: %~1   environment variable to store the timestamp to
:: %~2   predefined timestamp value to test
:: %~3   text that is displayed to ask for the timestamp value
   if "%~1" == "" echo missing parameter & exit /b 1
   if not exist "dummy\empty" md "dummy\empty"
   setlocal enableExtensions enableDelayedExpansion
   set "ts=%~2"
   if not defined ts set /P "ts=%~3"
   (
      set "ts"
   ) | (
      >nul findstr /R /C:"^ts=../../....,[0-1][0-9]:[0-5][0-9]:[0-5][0-9]$" /C:"^ts=../../....,2[0-3]:[0-5][0-9]:[0-5][0-9]$"
   ) && (
      2>nul xcopy /d:!ts:~0,10! /t "dummy\empty" "dummy"
   ) && (
      rd /s /q dummy
      endlocal & set "%~1=%ts%"
      exit /b 0
   )
   echo Invalid timestamp: !ts!.
   endlocal
   if not "%~2" == "" (
      call :ValidTimestamp "%~1" "" "%~3"
      exit /b
   )
   goto :ValidTimestamp

:setValidLabel
:: %~1   variable to set
:: %~2   default value; MUST be in format "label:name"
   setlocal disableDelayedExpansion
   set "iso_Volume_Label=%~2"
   set "first=1"

:validateLabel
   set "invalid="

   setlocal enableDelayedExpansion
   set "iso_Volume_Label= !iso_Volume_Label!"
   if "!iso_Volume_Label!" == " " set "invalid=Empty labels not allowed."
   if not defined invalid if not "!iso_Volume_Label:~33!" == "" set "invalid=More than 32 characters are not allowed for the volume label."
   if not defined invalid for /F "tokens=1-2 delims=_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" %%a in ("!iso_Volume_Label!") do (
      setlocal disableDelayedExpansion
      if not "%%~a" == " " (
         endlocal
         set "invalid=The only allowed characters are '_', '0', ... '9', 'a', ..., 'z', 'A', ..., 'Z'."
      ) else if not "%%~b" == "" (
         endlocal
         set "invalid=The only allowed characters are '_', '0', ... '9', 'a', ..., 'z', 'A', ..., 'Z'."
      ) else endlocal
   )
   endlocal & set "invalid=%invalid%" & ( if not defined invalid set "iso_Volume_Label=%iso_Volume_Label:~1%" )
   if defined invalid (
      if not defined first echo(%invalid%
      set "first="
      set "iso_Volume_Label="
      set /p "iso_Volume_Label=Please enter a valid volume label (UDF 1.02 volume identifier): "
      goto :validateLabel
   )
   endlocal & set "%~1=%iso_Volume_Label%"
   goto :eof


There are still errors?

Thanks

Bye

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: esd ---> iso script (Testing in progress)

#79 Post by Squashman » 01 Nov 2016 10:50

balubeto wrote:There are still errors?

Are you asking us if there are errors or telling us there are errors?

At what line of code does the error occur?

balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

Re: esd ---> iso script (Testing in progress)

#80 Post by balubeto » 01 Nov 2016 11:20

Squashman wrote:
balubeto wrote:There are still errors?

Are you asking us if there are errors or telling us there are errors?

At what line of code does the error occur?


I made the fixes suggested by penpen but I'm not sure if I have applied them correctly.

You can check if I made the right fixes?

Thanks

Bye

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: esd ---> iso script (Testing in progress)

#81 Post by penpen » 01 Nov 2016 14:11

You have nearly misunderstood 100% of what i've written; maybe i wasn't clear enough.

I said "you have added 3 changes (all are errors)", so i meant:
The original code was error free and your change causes the error <=> restore the original code again.

In addition i wrote "You have inserted line endings within the following ... command", this means:
The added line endings causes the error <=> remove the additional line endings.
I don't understand why you got the idea also to remove the referenced instructions in sections 1 and 2.

Same is in common true for the third point, but i didn't know what idea is behind your change;
so i don't know if something of this change may be useful regarding your aims, so i gave some tips what you should think of, if you want to improve that code.
Nevertheless i explicitely recommended to restore your code in section 3 to the before state:
"I recommend you to remove that part from the subroutine, and add it to the main code (where it was before - if i remember right) again."
(If you may have misunderstood its scope: This recommendation is only for point 3.)


So the corrected code should be something like this:

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion

call :setValidPath    "Windows_Files_Path" "%~1" "Enter the directory in which put the content of the 'Windows Setup Media' volume image:"   "absolutePath" "mayExist"   "directory"  "rw"
call :setValidPath    "iso_Path"           "%~2" "Enter the directory in which put the iso image file created:"                              "absolutePath" "mayExist"   "directory"  "--"
call :setValidPath    "iso_File"           "%~3" "Enter the iso file that will be saved in the %iso_Path% directory:"                        "relativePath" "mayExist"   "file"       "rw" "iso_Path"
call :IsoFile         "%iso_Path%"         "%iso_File%"
call :setValidPath    "esd_Path"           "%~4" "Enter the directory in which put the esd unencrypted file:"                                "absolutePath" "mustExist"  "directory"  "--"
call :setValidPath    "esd_File"           "%~5" "Enter the file to be converted which should be put in the %esd_Path% directory:"           "relativePath" "mustExist"  "file"       "rw" "esd_Path"
call :setValidLabel   "iso_Volume_Label"   "%~6"
call :ValidTimestamp  "Timestamp"          "%~7" "Enter a timestamp ('mm/dd/yyyy,hh:mm:ss') for all files and directories in the %iso_File%: "

echo(
echo Result:
echo Windows_Files_Path: "%Windows_Files_Path%"
echo iso_Path          : "%iso_Path%"
echo esd_Path          : "%esd_Path%"
echo esd_File          : "%esd_File%"
echo iso_File          : "%iso_File%"
echo iso_Volume_Label  : "%iso_Volume_Label%"
echo timestamp         : "%timestamp%"

:: put your code here

endlocal
goto :eof


:setValidPath
:: %~1   variable to set
:: %~2   default value
:: %~3   text if default value is invalid
:: %~4   Text equals: (forced to relativePath if %~6 equals file)
::     absolutePath  if path must be absolute
::     relativePath  if path must be relative
::     anyPath       if path may be relative or absolute (any other value)
:: %~5   Text equals: (forced to mayExist if %~8 does not exist)
::     mustExist     if file/directory must exist,
::     doesntExist   if file/directory is not allowed to exist.
::     mayExist      if file/directory may or may not exist (any other value).
:: %~6   Text equals:
::     file          if object to test is a file
::     directory     if object to test is a directory (any other value).
:: %~7   Text equals: (only checked if file/directory exists)
::     r             check read access for specified file/directory
::     w             check write access for specified file/directory
::     rw            check read and write access for specified file/directory
::     -             check no access for specified file/directory (any other value)
::     directory     if object to test is a directory (any other value).
::     Note: testing write access on a directory creates a file "test.tmp"
:: %~8   Only if /I %~6 == "file": environment variable with an path to store the file to
::   (forced to empty word, if %~6 equals directory).
::
 
   setlocal
   set "firstTime=1"
   set "input=%~2"
   set "text=%~3"
   if        "%~4" == "absolutePath" ( set "pathType=%~4"
   ) else if "%~4" == "relativePath" ( set "pathType=%~4"
   ) else set "existType=anyPath"
   if        "%~5" == "mustExist" ( set "existType=%~5"
   ) else if "%~5" == "doesntExist" ( set "existType=%~5"
   ) else set "existType=mayExist"
   setlocal enableDelayedExpansion
   set "parent= "
   if "%~6" == "file" (
      set "parent= !%~8!"
      if not "!parent:~-1!" == ":" (
         set "parent=!parent!\"
         if "!parent:~-2!" == "\\" set "parent=!parent:~0,-1!"
      )
   )
   endlocal & set "parent=%parent:~1%"
   if "%~6" == "file" (
      set "fileType=file"
      set "pathType=relativePath"
      if defined parent (
         if not exist "%parent%" set "existType=mayExist"
      ) else set "existType=mayExist"
   ) else set "fileType=directory"
   if        "%~7" == "r"  ( set "checkAccess=r-"
   ) else if "%~7" == "w"  ( set "checkAccess=-w"
   ) else if "%~7" == "rw" ( set "checkAccess=rw"
   ) else                  ( set "checkAccess=--"
   )

:validatePath
   :: validating
   set "invalid="
   call :isValidPathName "input" || goto :invalidatedPath
   if        /I     "%pathType%" == "absolutePath" ( call :isAbsolutePathName "input" || ( set "invalid=Path must be absolute" & goto :invalidatedPath )
   ) else if /I     "%pathType%" == "relativePath" ( call :isAbsolutePathName "input" && ( set "invalid=Path must be relative" & goto :invalidatedPath ) || >&2 >nul (echo @maybe: replace "<volume label>:" in !input!)
   )
   setlocal enableExtensions enableDelayedExpansion
   set "input=!parent!!input!"
   if        /I     "%existType%" == "mustExist"   ( if not exist "!input!" ( endlocal & set "invalid=Path must exist." & goto :invalidatedPath           )
   ) else if /I     "%existType%" == "doesntExist" ( if     exist "!input!" ( endlocal & set "invalid=Path must be non existent." & goto :invalidatedPath )
   )

   if exist "!input!" for %%b in ("!input!") do (
      set "attribs=%%~ab"
      if /I "%fileType%" == "file" (
         if not "!attribs:d=!" == "!attribs!" (
            endlocal & set "invalid=Path must denote a file (not a directory)." & goto :invalidatedPath
         ) else (
            if "%checkAccess:~0,1%" == "r" (
               2>nul <"!input!" set /p "check=" || (
                  for %%a in ("!input!") do if "%%~za" == "0" (
                     >&2 echo(Warning: Could not verify read access: Reason filesize of "!input!" is 0.
                  ) else (
                     endlocal & set "invalid=No read access (wanted)." & goto :invalidatedPath
                  )
               )
            ) else if "%checkAccess:~1,1%" == "w" 2>nul (
               >"!input!" <nul set /p "check=" || ( endlocal & set "invalid=No write access (wanted)." & goto :invalidatedPath )
            )
         )
      ) else (
         if "!attribs:d=!" == "!attribs!" (
            endlocal & set "invalid=Path must denote a directory (not a file)." & goto :invalidatedPath
         ) else (
            if "%checkAccess:~0,1%" == "r" 2>nul (
               >nul dir "!input!" || ( endlocal & set "invalid=No read access (wanted)." & goto :invalidatedPath )
            )
            if "%checkAccess:~1,1%" == "w" 2>nul (
               >nul pushd "!input!"
               >"test.tmp" echo test || ( >nul popd & endlocal & set "invalid=No write access (wanted)." & goto :invalidatedPath )
               >nul del "test.tmp"   || ( >nul popd & endlocal & set "invalid=No write access (wanted)." & goto :invalidatedPath )
               >nul popd
            )
         )
      )
   )

   endlocal
   endlocal & set "%~1=%input%"
   goto :eof

:invalidatedPath
   if defined invalid echo(Invalid: %invalid%
   set /P ^"input=%text:""="% "
   goto :validatePath
   goto :eof


:: Check if the pathname follows mainly the naming convention:
:: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
:: Exceptions:
::  - Only a drive descriptor (for example "C:") is allowed for volume names.
::  - Not tested if characters 0x00-0x31, or any other forbidden character (of the target filesystem) are present. (disallowed)
::  - Not tested on alternative data streams
:isValidPathName
:: %~1   environment variable containing the path to test.
   setlocal enableExtensions enableDelayedExpansion
   set "pathName=!%~1!"
   set "invalid="
   if not defined invalid if "!pathName!" == "" if defined firstTime (exit /b 1 & goto :test) else set "invalid=The pathname cannot be empty." & set "pathName= "
   if not defined invalid for /f tokens^=1^*^ delims^=^/^<^>^|^*^?^" %%a in ("#!pathName!#") do if not "%%~b" == "" set "invalid=Invalid character found."
   if not defined invalid set ^"pathname=!pathname:"=!"

   if not defined invalid (
      set "pathName= !pathName:/=\!"
>nul echo @maybe:set "pathName= !pathName:\..\=\!"
>nul echo @maybe:set "pathName= !pathName:\.\=\!"
>nul echo @maybe:if "%pathName:~-3%" == "\.." set "pathName= !pathName:~0,-3!"
>nul echo @maybe:if "%pathName:~-2%" == "\." set "pathName= !pathName:~0,-2!"
   )

   if not defined invalid if not "!pathName:\\=__!" == "!pathname!" set "invalid=Empty string is no valid path component."
   if not defined invalid if "!pathName:~1,1!" == ":" (
      for /f "tokens=1* delims=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" %%a in ("#!pathName:~0,1!#") do if not "%%~a" == "#" set "invalid=Invalid drive name."
      set "pathName=!pathName:~2!"
   )
   if not defined invalid 2>nul (
      echo(\!pathname!\|>nul findstr /I /R /C:"[\\]AUX[\\]" /C:"[\\]CON[\\]" /C:"[\\]NUL[\\]" /C:"[\\]PRN[\\]" /C:"[\\]COM[0-9][\\]" /C:"[\\]LPT[0-9][\\]" && (
         set "invalid=The following names are not allowed for file/directory names: CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9."
      )
   )
   if not defined invalid 2>nul (
      echo(\!pathname!\|>nul findstr /R /C:"[\ ][\\]" /C:"[\.][\\]" && (
         set "invalid=It is not allowed to end file/directory names with a space (' ') or a period ('.') character."
      )
   )
   if not defined invalid (
      endlocal
      exit /b 0
   ) else (
      endlocal & set "invalid=%invalid%"
      exit /b 1
   )
   goto :eof


:: Using mainly the definition of the Windows Shell API, see:
:: https://msdn.microsoft.com/en-us/library/windows/desktop/bb773660(v=vs.85).aspx
:: Exception:
::  - Only accepts a drive descriptor (for example "C:") is allowed for volume names.
::
:: does not check validity (must be valid)

:isAbsolutePathName
:: %~1   environment variable containing the path to test.
   setlocal enableExtensions enableDelayedExpansion
   if not "!%~1:~1,2!" == ":\" (
      endlocal
      exit /b 1
   ) else (
      endlocal
      exit /b 0
   )
   goto :eof

:IsoFile
   call :setValidPath   "iso_File"           "%~2"  "Enter the iso file (in the UDF 1.02 format) that will be saved in the %iso_Path% directory:"  "relativePath" "mayExist"   "file"       "-w" "iso_Path"
   call
   if exist "%~1\%iso_File%" choice /M "Iso File exists; overwrite it? " /C:YN
   if not "%errorlevel%" == "1" (
      if "%errorlevel%" == "0" echo(
      call :IsoFile "%~1" ""
   )
   goto :eof

:ValidTimestamp
:: Caution!
:: This function creates two subdirectories "dummy\empty".
:: Don't use these directories!
:: These directories were deleted automatically.
:: %~1   environment variable to store the timestamp to
:: %~2   predefined timestamp value to test
:: %~3   text that is displayed to ask for the timestamp value
   if "%~1" == "" echo missing parameter & exit /b 1
   if not exist "dummy\empty" md "dummy\empty"
   setlocal enableExtensions enableDelayedExpansion
   set "ts=%~2"
   if not defined ts set /P "ts=%~3"
   (
      set "ts"
   ) | (
      >nul findstr /R /C:"^ts=../../....,[0-1][0-9]:[0-5][0-9]:[0-5][0-9]$" /C:"^ts=../../....,2[0-3]:[0-5][0-9]:[0-5][0-9]$"
   ) && (
      2>nul xcopy /d:!ts:~0,10! /t "dummy\empty" "dummy"
   ) && (
      rd /s /q dummy
      endlocal & set "%~1=%ts%"
      exit /b 0
   )
   echo Invalid timestamp: !ts!.
   endlocal
   if not "%~2" == "" (
      call :ValidTimestamp "%~1" "" "%~3"
      exit /b
   )
   goto :ValidTimestamp

:setValidLabel
:: %~1   variable to set
:: %~2   default value; MUST be in format "label:name"
   setlocal disableDelayedExpansion
   set "iso_Volume_Label=%~2"
   set "first=1"

:validateLabel
   set "invalid="

   setlocal enableDelayedExpansion
   set "iso_Volume_Label= !iso_Volume_Label!"
   if "!iso_Volume_Label!" == " " set "invalid=Empty labels not allowed."
   if not defined invalid if not "!iso_Volume_Label:~33!" == "" set "invalid=More than 32 characters are not allowed for the volume label."
   if not defined invalid for /F "tokens=1-2 delims=_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" %%a in ("!iso_Volume_Label!") do (
      setlocal disableDelayedExpansion
      if not "%%~a" == " " (
         endlocal
         set "invalid=The only allowed characters are '_', '0', ... '9', 'a', ..., 'z', 'A', ..., 'Z'."
      ) else if not "%%~b" == "" (
         endlocal
         set "invalid=The only allowed characters are '_', '0', ... '9', 'a', ..., 'z', 'A', ..., 'Z'."
      ) else endlocal
   )
   endlocal & set "invalid=%invalid%" & ( if not defined invalid set "iso_Volume_Label=%iso_Volume_Label:~1%" )
   if defined invalid (
      if not defined first echo(%invalid%
      set "first="
      set "iso_Volume_Label="
      set /p "iso_Volume_Label=Please enter a valid volume label (UDF 1.02 volume identifier): "
      goto :validateLabel
   )
   endlocal & set "%~1=%iso_Volume_Label%"
   goto :eof


You should call it using (i called it test.bat):

Code: Select all

Z:\>test.bat "Z:\wfp" "Z:\iso" "iso.file" "Z:\esd" "esd.file" "isoVolLabel" "11/01/2016,21:13:00"
Warning: Could not verify read access: Reason filesize of "Z:\iso\iso.file" is 0.
Iso File exists; overwrite it? [Y,N]?Y
Warning: Could not verify read access: Reason filesize of "Z:\esd\esd.file" is 0.

Result:
Windows_Files_Path: "Z:\wfp"
iso_Path          : "Z:\iso"
esd_Path          : "Z:\esd"
esd_File          : "esd.file"
iso_File          : "iso.file"
iso_Volume_Label  : "isoVolLabel"
timestamp         : "11/01/2016,21:13:00"

Z:\>


penpen

balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

Re: esd ---> iso script (Testing in progress)

#82 Post by balubeto » 02 Nov 2016 11:27

I made some minor adjustments to the script

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion

call :setValidPath    "Windows_Files_Path" "%~1" "Enter the directory in which put the content of the 'Windows Setup Media' volume image:"   "absolutePath" "mayExist"   "directory"  "rw"
call :setValidPath    "iso_Path"           "%~2" "Enter the directory in which put the iso image file created:"                              "absolutePath" "mayExist"   "directory"  "--"
call :setValidPath    "iso_File"           "%~3" "Enter the iso file that will be saved in the %iso_Path% directory:"                        "relativePath" "mayExist"   "file"       "rw" "iso_Path"
call :IsoFile         "%iso_Path%"         "%iso_File%"
call :setValidPath    "esd_Path"           "%~4" "Enter the directory in which put the esd unencrypted file:"                                "absolutePath" "mustExist"  "directory"  "--"
call :setValidPath    "esd_File"           "%~5" "Enter the esd file to be converted which should be put in the %esd_Path% directory:"       "relativePath" "mustExist"  "file"       "rw" "esd_Path"
call :setValidLabel   "iso_Volume_Label"   "%~6"
call :ValidTimestamp  "Timestamp"          "%~7" "Enter a timestamp ('mm/dd/yyyy,hh:mm:ss') for all files and directories in the %iso_File%: "

echo(
echo Result:
echo Windows_Files_Path: "%Windows_Files_Path%"
echo iso_Path          : "%iso_Path%"
echo esd_Path          : "%esd_Path%"
echo esd_File          : "%esd_File%"
echo iso_File          : "%iso_File%"
echo iso_Volume_Label  : "%iso_Volume_Label%"
echo timestamp         : "%timestamp%"

:: put your code here

endlocal
goto :eof


:setValidPath
:: %~1   variable to set
:: %~2   default value
:: %~3   text if default value is invalid
:: %~4   Text equals: (forced to relativePath if %~6 equals file)
::     absolutePath  if path must be absolute
::     relativePath  if path must be relative
::     anyPath       if path may be relative or absolute (any other value)
:: %~5   Text equals: (forced to mayExist if %~8 does not exist)
::     mustExist     if file/directory must exist,
::     doesntExist   if file/directory is not allowed to exist.
::     mayExist      if file/directory may or may not exist (any other value).
:: %~6   Text equals:
::     file          if object to test is a file
::     directory     if object to test is a directory (any other value).
:: %~7   Text equals: (only checked if file/directory exists)
::     r             check read access for specified file/directory
::     w             check write access for specified file/directory
::     rw            check read and write access for specified file/directory
::     -             check no access for specified file/directory (any other value)
::     directory     if object to test is a directory (any other value).
::     Note: testing write access on a directory creates a file "test.tmp"
:: %~8   Only if /I %~6 == "file": environment variable with an path to store the file to
::   (forced to empty word, if %~6 equals directory).
::
 
   setlocal
   set "firstTime=1"
   set "input=%~2"
   set "text=%~3"
   if        "%~4" == "absolutePath" ( set "pathType=%~4"
   ) else if "%~4" == "relativePath" ( set "pathType=%~4"
   ) else set "existType=anyPath"
   if        "%~5" == "mustExist" ( set "existType=%~5"
   ) else if "%~5" == "doesntExist" ( set "existType=%~5"
   ) else set "existType=mayExist"
   setlocal enableDelayedExpansion
   set "parent= "
   if "%~6" == "file" (
      set "parent= !%~8!"
      if not "!parent:~-1!" == ":" (
         set "parent=!parent!\"
         if "!parent:~-2!" == "\\" set "parent=!parent:~0,-1!"
      )
   )
   endlocal & set "parent=%parent:~1%"
   if "%~6" == "file" (
      set "fileType=file"
      set "pathType=relativePath"
      if defined parent (
         if not exist "%parent%" set "existType=mayExist"
      ) else set "existType=mayExist"
   ) else set "fileType=directory"
   if        "%~7" == "r"  ( set "checkAccess=r-"
   ) else if "%~7" == "w"  ( set "checkAccess=-w"
   ) else if "%~7" == "rw" ( set "checkAccess=rw"
   ) else                  ( set "checkAccess=--"
   )

:validatePath
   :: validating
   set "invalid="
   call :isValidPathName "input" || goto :invalidatedPath
   if        /I     "%pathType%" == "absolutePath" ( call :isAbsolutePathName "input" || ( set "invalid=Path must be absolute" & goto :invalidatedPath )
   ) else if /I     "%pathType%" == "relativePath" ( call :isAbsolutePathName "input" && ( set "invalid=Path must be relative" & goto :invalidatedPath ) || >&2 >nul (echo @maybe: replace "<volume label>:" in !input!)
   )
   setlocal enableExtensions enableDelayedExpansion
   set "input=!parent!!input!"
   if        /I     "%existType%" == "mustExist"   ( if not exist "!input!" ( endlocal & set "invalid=Path or file must exist." & goto :invalidatedPath           )
   ) else if /I     "%existType%" == "doesntExist" ( if     exist "!input!" ( endlocal & set "invalid=Path must be non existent." & goto :invalidatedPath )
   )

   if exist "!input!" for %%b in ("!input!") do (
      set "attribs=%%~ab"
      if /I "%fileType%" == "file" (
         if not "!attribs:d=!" == "!attribs!" (
            endlocal & set "invalid=Path must denote a file (not a directory)." & goto :invalidatedPath
         ) else (
            if "%checkAccess:~0,1%" == "r" (
               2>nul <"!input!" set /p "check=" || (
                  for %%a in ("!input!") do if "%%~za" == "0" (
                     >&2 echo(Warning: Could not verify read access: Reason filesize of "!input!" is 0.
                  ) else (
                     endlocal & set "invalid=No read access (wanted)." & goto :invalidatedPath
                  )
               )
            ) else if "%checkAccess:~1,1%" == "w" 2>nul (
               >"!input!" <nul set /p "check=" || ( endlocal & set "invalid=No write access (wanted)." & goto :invalidatedPath )
            )
         )
      ) else (
         if "!attribs:d=!" == "!attribs!" (
            endlocal & set "invalid=Path must denote a directory (not a file)." & goto :invalidatedPath
         ) else (
            if "%checkAccess:~0,1%" == "r" 2>nul (
               >nul dir "!input!" || ( endlocal & set "invalid=No read access (wanted)." & goto :invalidatedPath )
            )
            if "%checkAccess:~1,1%" == "w" 2>nul (
               >nul pushd "!input!"
               >"test.tmp" echo test || ( >nul popd & endlocal & set "invalid=No write access (wanted)." & goto :invalidatedPath )
               >nul del "test.tmp"   || ( >nul popd & endlocal & set "invalid=No write access (wanted)." & goto :invalidatedPath )
               >nul popd
            )
         )
      )
   )

   endlocal
   endlocal & set "%~1=%input%"
   goto :eof

:invalidatedPath
   if defined invalid echo(Invalid: %invalid%
   set /P ^"input=%text:""="% "
   goto :validatePath
   goto :eof


:: Check if the pathname follows mainly the naming convention:
:: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
:: Exceptions:
::  - Only a drive descriptor (for example "C:") is allowed for volume names.
::  - Not tested if characters 0x00-0x31, or any other forbidden character (of the target filesystem) are present. (disallowed)
::  - Not tested on alternative data streams
:isValidPathName
:: %~1   environment variable containing the path to test.
   setlocal enableExtensions enableDelayedExpansion
   set "pathName=!%~1!"
   set "invalid="
   if not defined invalid if "!pathName!" == "" if defined firstTime (exit /b 1 & goto :test) else set "invalid=The pathname cannot be empty." & set "pathName= "
   if not defined invalid for /f tokens^=1^*^ delims^=^/^<^>^|^*^?^" %%a in ("#!pathName!#") do if not "%%~b" == "" set "invalid=Invalid character found."
   if not defined invalid set ^"pathname=!pathname:"=!"

   if not defined invalid (
      set "pathName= !pathName:/=\!"
>nul echo @maybe:set "pathName= !pathName:\..\=\!"
>nul echo @maybe:set "pathName= !pathName:\.\=\!"
>nul echo @maybe:if "%pathName:~-3%" == "\.." set "pathName= !pathName:~0,-3!"
>nul echo @maybe:if "%pathName:~-2%" == "\." set "pathName= !pathName:~0,-2!"
   )

   if not defined invalid if not "!pathName:\\=__!" == "!pathname!" set "invalid=Empty string is no valid path component."
   if not defined invalid if "!pathName:~1,1!" == ":" (
      for /f "tokens=1* delims=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" %%a in ("#!pathName:~0,1!#") do if not "%%~a" == "#" set "invalid=Invalid drive name."
      set "pathName=!pathName:~2!"
   )
   if not defined invalid 2>nul (
      echo(\!pathname!\|>nul findstr /I /R /C:"[\\]AUX[\\]" /C:"[\\]CON[\\]" /C:"[\\]NUL[\\]" /C:"[\\]PRN[\\]" /C:"[\\]COM[0-9][\\]" /C:"[\\]LPT[0-9][\\]" && (
         set "invalid=The following names are not allowed for file/directory names: CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9."
      )
   )
   if not defined invalid 2>nul (
      echo(\!pathname!\|>nul findstr /R /C:"[\ ][\\]" /C:"[\.][\\]" && (
         set "invalid=It is not allowed to end file/directory names with a space (' ') or a period ('.') character."
      )
   )
   if not defined invalid (
      endlocal
      exit /b 0
   ) else (
      endlocal & set "invalid=%invalid%"
      exit /b 1
   )
   goto :eof


:: Using mainly the definition of the Windows Shell API, see:
:: https://msdn.microsoft.com/en-us/library/windows/desktop/bb773660(v=vs.85).aspx
:: Exception:
::  - Only accepts a drive descriptor (for example "C:") is allowed for volume names.
::
:: does not check validity (must be valid)

:isAbsolutePathName
:: %~1   environment variable containing the path to test.
   setlocal enableExtensions enableDelayedExpansion
   if not "!%~1:~1,2!" == ":\" (
      endlocal
      exit /b 1
   ) else (
      endlocal
      exit /b 0
   )
   goto :eof

:IsoFile
   call :setValidPath   "iso_File"           "%~2"  "Enter the iso file that will be saved in the %iso_Path% directory:"  "relativePath" "mayExist"   "file"       "-w" "iso_Path"
   call
   if exist "%~1\%iso_File%" choice /M "Iso File exists; overwrite it? " /C:YN
   if not "%errorlevel%" == "1" (
      if "%errorlevel%" == "0" echo(
      call :IsoFile "%~1" ""
   )
   goto :eof

:ValidTimestamp
:: Caution!
:: This function creates two subdirectories "dummy\empty".
:: Don't use these directories!
:: These directories were deleted automatically.
:: %~1   environment variable to store the timestamp to
:: %~2   predefined timestamp value to test
:: %~3   text that is displayed to ask for the timestamp value
   if "%~1" == "" echo missing parameter & exit /b 1
   if not exist "dummy\empty" md "dummy\empty"
   setlocal enableExtensions enableDelayedExpansion
   set "ts=%~2"
   if not defined ts set /P "ts=%~3"
   (
      set "ts"
   ) | (
      >nul findstr /R /C:"^ts=../../....,[0-1][0-9]:[0-5][0-9]:[0-5][0-9]$" /C:"^ts=../../....,2[0-3]:[0-5][0-9]:[0-5][0-9]$"
   ) && (
      2>nul xcopy /d:!ts:~0,10! /t "dummy\empty" "dummy"
   ) && (
      rd /s /q dummy
      endlocal & set "%~1=%ts%"
      exit /b 0
   )
   echo Invalid timestamp: !ts!.
   endlocal
   if not "%~2" == "" (
      call :ValidTimestamp "%~1" "" "%~3"
      exit /b
   )
   goto :ValidTimestamp

:setValidLabel
:: %~1   variable to set
:: %~2   default value; MUST be in format "label:name"
   setlocal disableDelayedExpansion
   set "iso_Volume_Label=%~2"
   set "first=1"

:validateLabel
   set "invalid="

   setlocal enableDelayedExpansion
   set "iso_Volume_Label= !iso_Volume_Label!"
   if "!iso_Volume_Label!" == " " set "invalid=Empty labels not allowed."
   if not defined invalid if not "!iso_Volume_Label:~33!" == "" set "invalid=More than 32 characters are not allowed for the volume label."
   if not defined invalid for /F "tokens=1-2 delims=.,_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" %%a in ("!iso_Volume_Label!") do (
      setlocal disableDelayedExpansion
      if not "%%~a" == " " (
         endlocal
         set "invalid=The only allowed characters are '.', ',', '_', '0', ... '9', 'a', ..., 'z', 'A', ..., 'Z'."
      ) else if not "%%~b" == "" (
         endlocal
         set "invalid=The only allowed characters are '.', ',', '_', '0', ... '9', 'a', ..., 'z', 'A', ..., 'Z'."
      ) else endlocal
   )
   endlocal & set "invalid=%invalid%" & ( if not defined invalid set "iso_Volume_Label=%iso_Volume_Label:~1%" )
   if defined invalid (
      if not defined first echo(%invalid%
      set "first="
      set "iso_Volume_Label="
      set /p "iso_Volume_Label=Please enter a valid volume label (in the UDF 1.02 format): "
      goto :validateLabel
   )
   endlocal & set "%~1=%iso_Volume_Label%"
   goto :eof


and I realized that:

1) when I insert an iso exists, the "Warning: Could not verify read access: Reason filesize of "D:\Users\Public\Documents\Balubeto\Test_script\iso\<File_name>.iso" is 0." message is displayed. How do I avoid displaying this warning?

2) If I interrupt, with the Ctrl-C command, the script when I should write a timestamp, the dummy directory will not be deleted. It is possible to make sure that the ValidTimestamp routine does not create any temporary directory?

Thanks

Bye

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: esd ---> iso script (Testing in progress)

#83 Post by penpen » 02 Nov 2016 13:17

balubeto wrote:1) when I insert an iso exists, the "Warning: Could not verify read access: Reason filesize of "D:\Users\Public\Documents\Balubeto\Test_script\iso\<File_name>.iso" is 0." message is displayed. How do I avoid displaying this warning?
If a file has no data, you cannot test (with batch) whether a file has read access or not.
You wanted to include such a test, so the typical behaviour if that test cannot be performed is to display a warning:
Anything else should be irritating to any user (in case of a read protected input file).

In addition the warning should not be displayed on valid iso-files (with a filesize > 0), so i don't see any issue.

If you still don't want to see any warnings, just redirect stderr to nul (the warnings are printed to stderr) when calling the batch file:

Code: Select all

Z:\>2>nul test.bat "Z:\wfp" "Z:\iso" "iso.file" "Z:\esd" "esd.file" "isoVolLabel" "11/01/2016,21:13:00"
Iso File exists; overwrite it? [Y,N]?Y

Result:
Windows_Files_Path: "Z:\wfp"
iso_Path          : "Z:\iso"
esd_Path          : "Z:\esd"
esd_File          : "esd.file"
iso_File          : "iso.file"
iso_Volume_Label  : "isoVolLabel"
timestamp         : "11/01/2016,21:13:00"

Z:\>


balubeto wrote:2) If I interrupt, with the Ctrl-C command, the script when I should write a timestamp, the dummy directory will not be deleted. It is possible to make sure that the ValidTimestamp routine does not create any temporary directory?
Not if you want this easy to use method of checkig the date.
Beside this Ctrl-C/Ctrl-Break should not be the default way to terminate a batch program:
Why do you need such a program interruption?

If you need this kind of program exit, then you should create another batch (test2.bat), that calls your above batch (test.bat):

Code: Select all

@echo off
start "" /wait cmd /ctest.bat %*
>nul (2>nul rd /s /q dummy)
Note, that in this case another command-window is opened.


penpen

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: esd ---> iso script (Testing in progress)

#84 Post by Squashman » 02 Nov 2016 13:53

Whatever happened to K.I.S.S.?

Sometimes you can only make a script partially bullet proof. I have been writing batch files for my company for years. I try to code for every known idiot in the company but basically I tell them this. "This script has this intended purpose. I have trained you to use this program in this manner. This is how the program works. Don't make it try to do something it is not supposed to do!"

balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

Re: esd ---> iso script (Testing in progress)

#85 Post by balubeto » 03 Nov 2016 10:14

penpen wrote:
balubeto wrote:1) when I insert an iso exists, the "Warning: Could not verify read access: Reason filesize of "D:\Users\Public\Documents\Balubeto\Test_script\iso\<File_name>.iso" is 0." message is displayed. How do I avoid displaying this warning?
If a file has no data, you cannot test (with batch) whether a file has read access or not.
You wanted to include such a test, so the typical behaviour if that test cannot be performed is to display a warning:
Anything else should be irritating to any user (in case of a read protected input file).

In addition the warning should not be displayed on valid iso-files (with a filesize > 0), so i don't see any issue.

penpen


I modified the IsoFile routine in this way

Code: Select all

:IsoFile
   call :setValidPath   "iso_File"           "%~2"  "Enter the iso file that will be saved in the %iso_Path% directory:"  "relativePath" "mayExist"   "file"       "-w" "iso_Path"
   call
   if exist "%~1\%iso_File%" choice /M "Iso File exists; overwrite it? " /C:YN 2>nul
   if not "%errorlevel%" == "1" (
      if "%errorlevel%" == "0" echo(
      call :IsoFile "%~1" ""
   )
   goto :eof


but the warning is still displayed. Where did I go wrong?

Thanks

Bye

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: esd ---> iso script (Testing in progress)

#86 Post by penpen » 04 Nov 2016 03:29

balubeto wrote:Where did I go wrong?
The choice command doesn't produce that error.
It is the ":setValidPath" function that produces this error.
If you really don't want to output this message, then you have to "null the stderr" when calling these functions for the specified files (in the main routine):

Code: Select all

call :setValidPath    "Windows_Files_Path" "%~1" "Enter the directory in which put the content of the 'Windows Setup Media' volume image:"   "absolutePath" "mayExist"   "directory"  "rw"
call :setValidPath    "iso_Path"           "%~2" "Enter the directory in which put the iso image file created:"                              "absolutePath" "mayExist"   "directory"  "--"
2>nul call :setValidPath    "iso_File"           "%~3" "Enter the iso file that will be saved in the %iso_Path% directory:"                        "relativePath" "mayExist"   "file"       "rw" "iso_Path"
call :IsoFile         "%iso_Path%"         "%iso_File%"
call :setValidPath    "esd_Path"           "%~4" "Enter the directory in which put the esd unencrypted file:"                                "absolutePath" "mustExist"  "directory"  "--"
2>nul call :setValidPath    "esd_File"           "%~5" "Enter the file to be converted which should be put in the %esd_Path% directory:"           "relativePath" "mustExist"  "file"       "rw" "esd_Path"
call :setValidLabel   "iso_Volume_Label"   "%~6"
call :ValidTimestamp  "Timestamp"          "%~7" "Enter a timestamp ('mm/dd/yyyy,hh:mm:ss') for all files and directories in the %iso_File%: "
(Please note (again): I recommend to display this message in such a case, because it gives you a hint if one of these files is null sized and read protected and reading failed.)


penpen

Post Reply