dragging input file to batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Amin
Posts: 20
Joined: 30 May 2011 05:25

dragging input file to batch

#1 Post by Amin » 12 Oct 2011 14:16

HI
i have the following behaviour!! when dragging an input file to a BATCH file.

when using sort %1 >>out.txt ,the output file does not appear in the working directory ,however,if i use the command : type out.txt there is an output.

@echo off
sort %1 >>f4.txt //No output file APPEARS in the current directory
type f4.txt // there is a correct output
pause



PLease Why ?

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: dragging input file to batch

#2 Post by Ed Dyreen » 12 Oct 2011 16:09

'
Test this:

Code: Select all

@echo off

echo.
echo.working directory: '%CD%'
> "ou.TMP" echo.This Works
if exist "ou.TMP" (
   echo. file exists in working directory: '%CD%'
)
del /f /q "ou.TMP"

pause
exit /b 0

Amin
Posts: 20
Joined: 30 May 2011 05:25

Re: dragging input file to batch

#3 Post by Amin » 13 Oct 2011 04:13

I tried it

I conclude the following:
-When running the file normaly(NO drag input file) ,the working directory is the folder you created the batch file in:
eg: "c:\documents and settings\administrator\desktop\new folder"

-When dragging the input file to the batch,the working directory is:
"c:\documents and settings\administrator"


I want all my files due to >> or > redirection to be written to the current directory in which the batch is running,
i used >>"%~dp0\output.txt" and >"%~dp0\output.txt"
this is working well.



Thank you

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: dragging input file to batch

#4 Post by Ed Dyreen » 13 Oct 2011 05:05

'
Did you know you can push &pop dirs ?

Code: Select all

pushd "%~dp0\"
::(
   echo.do things here :)
::)
popd
or without going back:

Code: Select all

cd "%~dp0\"

Amin
Posts: 20
Joined: 30 May 2011 05:25

Re: dragging input file to batch

#5 Post by Amin » 13 Oct 2011 05:08

I didn't use it before .
Thank you very much !
:)

Post Reply