Reputation: 371
I see this question has been asked from time to time, but no answer has been given which solves the problem for me.
The following batch reproduces the problem
@echo off
sleep 2
dir /s /b > FileList.txt
When running batch from command line it runs as expected. It sleeps for 2sec and then creates the file FileList.txt
But when double clicking in file browser, then only the sleep command seems to execute. The FileList.txt does not get created. The Dir command is executing, but the file is not created.
I have tried by running with admin rights to no help.
cmd /c assoc .bat
gives
.bat=batfile
Registry has been checked and found OK. So... Is there a way to get batch files run by clicking on them to also handle file operations? Because thats what I believe is the issue here that something is preventing file operations to happen when evoked from a batch script which runs from within a file browser.
Upvotes: 1
Views: 1458
Reputation: 82390
When starting a batch by double click from the explorer the working directory hasn't be the same as the batch file itself.
You can solve this by using an absolute path
@echo off
sleep 2
dir /s /b > c:\temp\FileList.txt
or by changing the working directory to the batch location.
@echo off
cd "%~dp0"
sleep 2
dir /s /b > FileList.txt
Upvotes: 1