1

I want to write a script that move files which dropped on it to somewhere. So this is how my batch code goes:

@echo off
for %%i in (%*) do move "%%~i" "somewhere\%%~nxi"
pause

Then I find that when I drop a file with the name that contains ')' and does not contain a space (eg. fig(1).jpg) it will report an error that says "There should be no .jpg)".

I know that it is fine if I write ./xxx.bat "fig(1).jpg" in terminal straightly, but I do need to drop some files on it. any help?

phuclv
  • 37,963
  • 15
  • 156
  • 475
yqZhang4480
  • 168
  • 5

1 Answers1

0

Use PowerShell instead. Just save this as move-to-somewhere.ps1

ls $args | mv -d "somewhere"

Then create a new shortcut and paste this

powershell.exe -noprofile -noexit -f path\to\move-to-somewhere.ps1

Now just drag the files you want to the newly created shortcut and they'll be moved as expected

The full command is Get-ChildItem -LiteralPath $args | Move-Item -Destination "somewhere" and you can also append -WhatIf/-wi to do a dry run before actually moving the files

In fact it should be easier but for some reason the methods to make drag-and-drop files on *.ps1 file directly don't work and the simplest temporary workaround is to use a shortcut. You can also create a batch file and forward all arguments to PowerShell but the file contents will be slightly different. For more information as well as other methods read

phuclv
  • 37,963
  • 15
  • 156
  • 475