Run MS-DOS Batch Function from current directory

I'm new to Directory Opus and already learned and customised my copy quite a bit, now I'm trying to create a button with my bat file, the bat file works as intended when double-clicked directly, but cannot get it to work when in a button.

This bat creates a small folder structure on whichever folder is placed, more precisely, 5 folders next to each other, and also 2 subfolders on one of the folders just created, then, it takes a specific image from a fixed place on my pc, and put a copy on each of the folders/subfolders just created.

@Echo Off
SetLocal EnableExtensions
For %%G In (
    "1.Capture\Selected"
    "1.Capture\Discard"
    "2.Projects"
    "3.Masters"
    "4.Web"
    "5.Instagram"
) Do %SystemRoot%\System32\xcopy.exe ""C:\Users\farig\Desktop\Placeholder.jpg"" "%~dp0%%~G\" /CHIKQRY 1>NUL

At the moment kind of works, it creates the structure and copies the image, but on the "Temp" folder instead of the folder that I'm at with DO. I'm guessing that I'm missing some sort of command to make run the command in the current folder

Any input?

Kind Regards,
Giovanni.

Try adding a line with cd {sourcepath$} at the start.

1 Like

Thanks, but it does not work, I tried to put it in a different position, starting from the beginning as you suggested. I'm also keeping track with Everything to see if it creates it in some random location but nothing.

%~dp0 in a batch file expands to the folder that the batch file is in; so you are specifically telling it to write to the same folder as the batch file, overriding the current directory.

2 Likes

Removing that part from the code did the trick, thanks.