# Solved: Use selected files - batch



## battlefielder (Apr 10, 2009)

Hello,

I'm trying to make a batch script which will copy the currently selected files to an external hard drive and deletes them afterwards.
(Files I want to delete, but might be important)

Can you put the paths of the currently selected files into a variable?
Or do you need a program to do that?

example:
I select file:
aaa.exe
bvd.txt
new.doc

I run the script and the three files will be exported to my external harddrive. The previously selected files will then be deleted.

Anyone knows how to do this?


----------



## john1 (Nov 25, 2000)

Hi,

have you tried right click, drag and drop, choose 'Move here'?
This will copy them to a connected external drive,
then delete them from where they were.

It might be quicker than writing a batch file.

John


----------



## TheOutcaste (Aug 8, 2007)

Highlight the files, right click, point to Send To, click on the icon for the external drive. This will copy them to the root of the drive.
Then press delete to delete them once they are all copied.

If you want to place them into a folder, create a shortcut to the folder and put it in the SendTo folder. Then use the shortcut instead of the drive icon.
The SendTo folder is here: *%userprofile%\SendTo*

To use a batch file you would have to drag and drop the files onto the batch file. The following will work:

```
@echo Off
Set _ExtDrivePath=N:\Test\
:_Start
If [%1==[ Goto :EOF
Move /Y %1 %_ExtDrivePath%
Shift
Goto _Start
```
The /Y switch will for it to overwrite existing files. If you want to be prompted, remove the /Y.
The folder must already exist on the external, or the files will be concatenated. You could add a check for that.

HTH

Jerry


----------



## battlefielder (Apr 10, 2009)

I know it's quicker to move and drop =D , but I want to use a hotkey to start the batch file. When you the typ "ctrl + delete" the selected files will automaticly be moved away. Some sort of "delete " function. It would also be good to use if you want to rename, or just for installation input.

I'm starting to beleve it's impossible to use selected files as an input.
If anyone knows a trick, I would be happy =D


----------



## battlefielder (Apr 10, 2009)

btw:
==============================
@echo Off
Set _ExtDrivePath=N:\Test\
:_Start
If [%1==[ Goto :EOF
Move /Y %1 %_ExtDrivePath%
Shift
Goto _Start
==============================
works fine. I'm now thinking of making a shortcut on my desktop
with a ashtray logo on it. Then I can do the same thing. 
Anyway thanks for your help!


----------



## battlefielder (Apr 10, 2009)

Thank you very much TheOutcaste! 
I changed the batch a little:


```
@echo Off
:Start
if not exist "L:\BACKUP\temp_deleted_files" goto :nodrive
if exist %1 goto movef
START %SystemRoot%\explorer.exe "L:\BACKUP\temp_deleted_files"
exit
:movef
cls
color 0A
echo Moving files to External Hard Drive...
echo.
Move /Y %1 "L:\BACKUP\temp_deleted_files"
Shift
Goto Start
:nodrive
cls
color 0C
echo Please start your external hard drive!
ECHO.
pause
exit
```
- When you drop a file in the batch, the file moves to external drive
- When you open the batch the folder containing the files will open.

It works perfectly.

(you could use a shortcut as well, but when the drive isn't connected, the shortcut wouldn't work or even disappear, now you get a message)


----------



## TheOutcaste (Aug 8, 2007)

Looks pretty good to me.

Couple of suggestions.

If the drive isn't found at first, you could ask if they want to retry or exit. This way they wouldn't have to drag the files over to the Icon again.

Also, set a flag once the drive is present. Then you can tell if the drive was disconnected or powered off in the middle of the process. Offering a retry/exit here would also allow continuing from the current spot once reconnected, instead of starting over.

Jerry


----------



## battlefielder (Apr 10, 2009)

Updated again, now the process will continue when the e. drive is found. :up:


```
@echo Off
:Start
if not exist "L:\BACKUP\temp_deleted_files" goto :nodrive
if exist %1 goto movef
START %SystemRoot%\explorer.exe "L:\BACKUP\temp_deleted_files"
exit
:movef
cls
color 0A
echo Moving files to External Hard Drive...
echo.
If [%1==[ Goto :EOF
Move /Y %1 "L:\BACKUP\temp_deleted_files"
Shift
Goto movef
:nodrive
cls
color 0C
echo Please start your external hard drive
ECHO.
:nodrive2
PING 1.1.1.1 -n 1 -w 1000 >NUL
if exist "L:\BACKUP\temp_deleted_files" goto connected
if not exist "L:\BACKUP\temp_deleted_files" goto nodrive2
:connected
cls
color 0A
echo Hard drive is online
echo.
pause
goto start
```
I think this thread is closed, because there is no way you can use "selected" files in a batch. 

Thanks for your help


----------

