0

I need to call zipjs.bat file which takes path as argument. I am calling the .bat file trough another .bat file called start.bat. Both files aren't at the same place in the file system, they reside in different folders.

zipjs.bat reside in \batch and the start.bat resides in \odt

The file that is to be passed as an argument to zipjs.bat resides in the same folder as start.bat.

This way(using absolute path for -source) everything works fine:

call ..\batch\zipjs.bat unzip -source C:\Users\rmrd001\git\xslt-framework\Product\dita\transformations\paragraphs\odt\source.odt.zip -destination .\MyDir -keep yes -force no
pause

Above the -source takes absolute path. But when I change the absolute path with relative one, like this: -source .\source.odt.zip it doesn't work. I tried with paths relative to start.bat - .\source.odt.zip and relative to zipjs.bat - ..\odt\source.odt.zip without success though.

Radoslaw Krasimirow
  • 1,833
  • 2
  • 18
  • 28
  • Possible duplicate of [Resolve absolute path from relative path and/or file name](http://stackoverflow.com/questions/1645843/resolve-absolute-path-from-relative-path-and-or-file-name) – wOxxOm Nov 17 '15 at 15:56
  • 1
    Since the START.bat and your source are one in the same then just use the directory the batch file exists in. `%~dp0` – Squashman Nov 17 '15 at 15:57

1 Answers1

1

The perhaps easiest method would be using %~dp0 which expands to path of start.bat ending with a backslash as suggested by Squashman.

I suggest additionally to clean up the directory for temporary files after making the decompression as zipjs.bat currently updated last time on 2015-03-17 by npocmaka does not do it, see answer on How to write a batch file that can unzip a file into a new folder with the same name?

@echo off
call ..\batch\zipjs.bat unzip -source "%~dp0source.odt.zip" -destination .\MyDir -keep yes -force no
for /F "delims=" %%D in ('dir /AD /B "%TEMP%\*source.odt.zip" 2^>nul') do (
    %SystemRoot%\System32\attrib.exe -h "%TEMP%\%%~D"
    rd /S /Q "%TEMP%\%%~D" 2>nul
)
pause
Community
  • 1
  • 1
Mofi
  • 46,139
  • 17
  • 80
  • 143
  • After running the for loop, remains a file named `nul)` and no further command are executed into the bat file. – Radoslaw Krasimirow Nov 18 '15 at 10:33
  • Are you sure that you use the code EXACTLY as I posted? Do you have tried those 7 lines? I suppose you use a slightly different batch file with redirecting a possible error messages of command __dir__ to device __nul__ wrong resulting in redirecting output to a file `nul)`. Please check your code and compare it with my code character by character. – Mofi Nov 18 '15 at 20:55