Question

Locked

How to pass filename from Windows to DOS?

By ahmad ·
Hi,

Is there anyway to pass a selected filename to DOS shell. Following scenario will explain the question better.

A person right clicks on a file (let's say abc.txt) in Windows Explorer and clicks on "Mark Reviewed" (as an example). It should open Dos shell (cmd.exe) and executes "move abc.txt C:\Reviewed\"

I can add "Mark Reviewed" to the context menu using registry and also open cmd.exe but once DOS shell is open I do not know which file was selected.

I implemented similar for Folders and that works but I could not figure our for Files. Below is the script for Folders.

**********SCRIPT BEGINS****************

cd %1
cd > %temp%\TEMPdir.txt
FOR /F "delims=" %%a in (%temp%\TEMPdir.txt) do set foldertomove=%%a
del %temp%\TEMPdir.txt
move "%foldertomove%" C:\Reviewed

********SCRIPT ENDS******************

Any suggestions?

Ahmad

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Well I wonder

by Tony Hopkinson In reply to How to pass filename from ...

why you don't just move the file in the context action....
But if you want to do it in the shell

The you create a cmd file with "Move abc.txt C:\Reviewed" as the content and then execute that in the shell and then to be neat delete the cmd file.

You if you can find one that will fit can find a bit of coe that will do this for you, personally I'd try to avoid using the shell at all for this.

Collapse -

Re: Well I wonder

by ahmad In reply to Well I wonder

Consider following folders and subfolders.

> Job1
>> Not Reviewed
>> Reviewed
> Job2
>> Not Reviewed
>> Reviewed
> Job3
>> Not Reviewed
>> Reviewed

Employees pick a file from "Not Reviewed" folder. Once the file has been reviewed, it should be moved to "Reviewed" Folder which may be hidden from that specific employee.

So I needed to either add a button in toolbar or an option in the context menu which would move that file to "Reviewed" folder specific to that Job (Job1, Job2, etc.)

Since destination folder could be different for each job so I needed to determine the path dynamically.

Below is the working script that solved my problem.

cd..
cd > %temp%\Tempdir.txt
FOR /F "delims=" %%a in (%temp%\Tempdir.txt) do set parentdir=%%a
del %temp%\Tempdir.txt
move %1 "%parentdir%\Reviewed

Collapse -

Ah well it looked like a nail, and I had this hammer

by Tony Hopkinson In reply to Re: Well I wonder

I could do it in code in minutes, scripting is something I rarely do, under windows anyway.

Collapse -

I think this may be easier to do as VBScript

by robo_dev In reply to How to pass filename from ...

This way you could skip having to invoke the cmd shell, since Vbscript is part of Windows.

Example of passing environment variables in vbscript:
http://www.watchdirectory.net/cgi-bin/yabb2/YaBB.pl?num=1195168136/2

example of copying files with vbscript
http://www.computerperformance.co.uk/ezine/ezine36.htm

Collapse -

thanks

by ahmad In reply to I think this may be easie ...

i didn't think about vbscript at all. i will look if that works in my situation or not.

in the meantime i found that "%1" variable already contains the filename and path so that made life much easier.

If in DOS shell I simply run

move %1 C:\Reviewed

that works.

Thanks everyone.

Back to Windows Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums