[SOLVED] Output gets directed to the wrong folder!
Posted: 08 Aug 2020 11:21
Good evening,
Part 1:
I have a .bat file named "Report.bat".
If I run "Report.bat" the output goes to the desktop . . .
I then use this for the "Report.txt" file output . . .
That all works great.
Part 2:
Now I have a folder named "PBU" with sub folders "bin" and "Reports".
Within the root of "PBU" I have a .bat file named "PBU_Program.bat".
I have put the "Report.bat" file in the "bin" folder.
From "PBU_Program.bat" I call the "Report.bat".
In the "Report.bat" to get it to output to the "PBU\Reports" folder instead of the desktop I changed . . .
. . . to . . .
Whatever I seem to do I can NOT get it to output to the "PBU\Reports" folder.
On the numerous attempts I have tried it mainly gets saved to the "PBU\bin" folder.
What am I doing wrong please?
Thanks in advance.
EDIT:
I did find one way that regardless of where the "PBU_Program.bat" was run from it would still save in the "PBU\Reports" folder as long as it's run from the folder named "PBU" with sub folders "bin" and "Reports" . . .
The only down side is obviously that it will no longer run as a standalone .bat file from the desktop for example because there is no "Reports" folder to output to, but I can live with that. I can just comment out . . .
. . . and replace it with . . .
Part 1:
I have a .bat file named "Report.bat".
If I run "Report.bat" the output goes to the desktop . . .
Code: Select all
set "Output_File=%DesktopFolder%\Report.txt"
Code: Select all
> "%Output_File%"
Part 2:
Now I have a folder named "PBU" with sub folders "bin" and "Reports".
Within the root of "PBU" I have a .bat file named "PBU_Program.bat".
I have put the "Report.bat" file in the "bin" folder.
From "PBU_Program.bat" I call the "Report.bat".
In the "Report.bat" to get it to output to the "PBU\Reports" folder instead of the desktop I changed . . .
Code: Select all
set "Output_File=%DesktopFolder%\Report.txt"
Code: Select all
cd /d "%~dp0"
set "Output_File=%~dp0Reports\Report.txt"
On the numerous attempts I have tried it mainly gets saved to the "PBU\bin" folder.
What am I doing wrong please?
Thanks in advance.
EDIT:
I did find one way that regardless of where the "PBU_Program.bat" was run from it would still save in the "PBU\Reports" folder as long as it's run from the folder named "PBU" with sub folders "bin" and "Reports" . . .
Code: Select all
set "Output_File=%cd%\Reports\Report.txt"
Code: Select all
set "Output_File=%cd%\Reports\Report.txt"
Code: Select all
set "Output_File=%DesktopFolder%\Report.txt"