Page 1 of 1

Drag and Drop Function

Posted: 22 Aug 2014 11:25
by xhai
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

Re: Drag and Drop Function

Posted: 22 Aug 2014 15:08
by ShadowThief

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

Re: Drag and Drop Function

Posted: 22 Aug 2014 20:46
by xhai
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 %*

Re: Drag and Drop Function

Posted: 22 Aug 2014 21:20
by ShadowThief
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