Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drag and drop files into console to get their path and filename?

Status
Not open for further replies.

ug505

Programmer
Jan 2, 2010
52
US
I have a console application that I want to show the path and filename when a file is dropped on it...kind of like the Command Prompt. Open Command Prompt and drag any file onto it and it will display the path and filename where you type. How can I get my console to do that?
 
The console provides this by entering the full file path into the input line. As a console application uses the same console you can just take advantage of this existing feature by telling your program to accept input.

This simple test application worked for me:

Code:
Module Module1

    Sub Main()
        Dim file As String = Console.ReadLine()
        Console.WriteLine(file)
        Console.ReadKey()
    End Sub

End Module

When I ran the program and dropped a file from my desktop, the full path showed up on the first line. Hitting "Enter" then re-displayed that file, and waited for a final key press to exit.
 
Upon testing your code in a new console application in Visual Basic 2010, I tried to drag a zip file onto the console application. It did not display a file path or file name. When I tried to drag it, it changed my cursor to the "no symbol" or the circle with a diagonal line through it. I'm running it on Windows Vista.
 
Sorry it took a while to respond - I've been a bit busy, and only now had a chance to research the problem.

From the research I've found, it looks like with Vista they dropped the Drag & Drop feature from the Command Prompt window. There do appear to be some work-arounds, that usually deal with a supplemental software install to re-enable that functionality.

My test was done on a Windows 7 machine, and I know I didn't install supplemental software for this - so it looks like they brought the Drag & Drop back.
 
Oh okay. Thanks for trying to help me. I guess I'll make my application in a standard Windows Application. Thanks. I did not know about Vista dropping Drag & Drop on Consoles. :/
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top