Drag and Drop Function

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
xhai
Posts: 39
Joined: 13 Jun 2013 09:33

Drag and Drop Function

#1 Post by xhai » 22 Aug 2014 11:25

Hi there guys will it be possibele to add a drag and drop function to these codes, the fname do changes frequently to script have a syntax of "script.py -e fname"

Code: Select all

@echo off
IF ["%1"] EQU [""] GOTO :eof
CD "%~dp0"
script.py -e %*


The Code doesn't work because the syntax is error..
I echo "%*" it display the drive ex. H:\fname

script.py -e %* = script.py -e H:\fname

In order to work the syntax should be "script.py -e fname"


Thank you

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Drag and Drop Function

#2 Post by ShadowThief » 22 Aug 2014 15:08

Code: Select all

@echo off
IF ["%1"] EQU [""] GOTO :eof
CD "%~dp0"
script.py -e %~nx1


This will take H:\folder\wherever\data.txt as input and run script.py -e data.txt

xhai
Posts: 39
Joined: 13 Jun 2013 09:33

Re: Drag and Drop Function

#3 Post by xhai » 22 Aug 2014 20:46

ShadowThief wrote:

Code: Select all

@echo off
IF ["%1"] EQU [""] GOTO :eof
CD "%~dp0"
script.py -e %~nx1


This will take H:\folder\wherever\data.txt as input and run script.py -e data.txt


Thanks ShadowThief

"%~nx1" removes the path while "%*" display the path

I just check my code again and it also work, I wonder what causes the problem last night

Code: Select all

@echo off
IF ["%1"] EQU [""] GOTO :eof
CD "%~dp0"
script.py -e %*

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Drag and Drop Function

#4 Post by ShadowThief » 22 Aug 2014 21:20

Yeah, the n takes H:\folder\whatever\file.txt and returns "file" and the x returns ".txt"

Read more here: http://ss64.com/nt/syntax-args.html

Post Reply