NO

Author Topic: File location  (Read 9160 times)

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: File location
« Reply #15 on: March 27, 2010, 04:13:21 AM »
Quote
Well, I am not sure that you get any window handle in a true console program

The console does indeed run inside a window and it is possible to get the handle of that window.

I once launched a windows dialog from the console, then, by artful means, got the consol window's handle.  I then set the dialog I created to be the consol window's parent.

Quote
[T]he only way to accomplish what the OP seems to try and achieve would be via commandline arguments, and I assume that this is what DMac tried to say (I guess)...

I tried to give the OP enough clues to find the solution without giving him the actual solution.  However I guess I was not clear enough.

I found that I could simply launch cmd.exe from my console app just as I would do it manually by Start>Run and typing "cmd.exe /k cd c:\"

What is realy happening is that my console app runs, launches another command prompt, and exits.
The command prompt that I launched remains open and I can drag a file into it and see the path to the file echoed there.

DMac
Sorry, but I think you really need a bit more detailed as to how the console program is getting the path of the drag&dropped file, all that you describe above is the indeed normal behavior of a windows command prompt (that it echoes the file path) but that doesn't mean at all that a console program running in the "DOS Shell/Command prompt" has any knowledge of that path...  ???

I have the feeling that we are talking about different things here, you seem to be talking of the command/shell process (cmd.exe) itself, not about a program, written in (Pelle's C) that is running on top of this very same command prompt/DOS Shell...

Ralf

Offline DMac

  • Member
  • *
  • Posts: 272
Re: File location
« Reply #16 on: March 29, 2010, 06:04:31 PM »
Quote
I have the feeling that we are talking about different things here, you seem to be talking of the command/shell process (cmd.exe) itself, not about a program, written in (Pelle's C) that is running on top of this very same command prompt/DOS Shell...

Ralf

Correct, the solution I had in mind was to simply launch another instance of the command prompt and exit.  The command prompt, I launched, by default then satisfies the assignment.  That is, to drag a file into the command prompt and have it display the path.  The OP said nothing about the application knowing the path.  Simply displaying the path of a file dragged and dropped in the command prompt window.
No one cares how much you know,
until they know how much you care.

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: File location
« Reply #17 on: March 30, 2010, 06:32:33 PM »
Quote
I have the feeling that we are talking about different things here, you seem to be talking of the command/shell process (cmd.exe) itself, not about a program, written in (Pelle's C) that is running on top of this very same command prompt/DOS Shell...

Ralf

Correct, the solution I had in mind was to simply launch another instance of the command prompt and exit.  The command prompt, I launched, by default then satisfies the assignment.  That is, to drag a file into the command prompt and have it display the path.  The OP said nothing about the application knowing the path.  Simply displaying the path of a file dragged and dropped in the command prompt window.
I think that was a bit oversimplified, specially considering that the original question might not have been that clear due to language issues...

Ralf

Tsiku

  • Guest
Re: File location
« Reply #18 on: March 30, 2010, 06:56:53 PM »
ok this is what i have so far

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
   char *cKv = "C:\\Windows\\System32\\cmd.exe /Q /C";
   FILE *fp = _popen(cKv, "r");
   char buf[255];
   int i = 0;
   while (fgets(buf, sizeof(buf), fp)) ;
   char b[255];
   char *a = gets(b);
   printf("1 file %s\n", b);
   a = gets(b);
   printf("2 file %s\n", b);
   system("pause");
   _pclose(fp);
   return 0;
}


decided to use cmd for it, and now can u help me make this programm also so it switches files locations
like about so

New Folder\folder\file1.exe
New Folder(2)\folder\file2.exe

and after switch its so

New Folder\folder\file2.exe
New Folder(2)\folder\file1.exe

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: File location
« Reply #19 on: March 31, 2010, 10:37:06 AM »
If this is homework, just this
- make 2 buffers for new path/file and copy old paths to those.
- find last occurrence of '\' and put those into pointers. (strrchr()?)
- strip filenames from new buffers using those pointers.
- copy switched filenames to new buffers using pointers. (strcat()?)
- move those files to new places. (rename()?)
May the source be with you