Page 1 of 1

dragging input file to batch

Posted: 12 Oct 2011 14:16
by Amin
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 ?

Re: dragging input file to batch

Posted: 12 Oct 2011 16:09
by Ed Dyreen
'
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

Re: dragging input file to batch

Posted: 13 Oct 2011 04:13
by Amin
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

Re: dragging input file to batch

Posted: 13 Oct 2011 05:05
by Ed Dyreen
'
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\"

Re: dragging input file to batch

Posted: 13 Oct 2011 05:08
by Amin
I didn't use it before .
Thank you very much !
:)