简体   繁体   English

在 sendTo 中对选定文件进行排序

[英]Sort selected files in sendTo

What's the way to sort a list of files, which is processed by a batch-file via sendTo-menu, eg:对文件列表进行排序的方法是什么,这些文件由批处理文件通过 sendTo-menu 处理,例如:

myDir
  file_1.txt
  file_3.txt
  hello.world
  foo.bar

If I mark these files and call a batch file via sendTo-link to process those files, the order of the files seems to be random:如果我标记这些文件并通过 sendTo-link 调用批处理文件来处理这些文件,则文件的顺序似乎是随机的:

FOR %%A IN (%*) DO (set command=!command! %%A)
ECHO %command%

In some cases this shoud make no difference, but for merging for example, it does.在某些情况下,这应该没有什么区别,但对于例如合并,它确实如此。

Something like using dir"*.sql ^| sort does not seem to work thus selected filenames are not considered.使用dir"*.sql ^| sort的东西似乎不起作用,因此不考虑选定的文件名。

@echo off
setlocal

rem Sort args stored if 1st argument is /sort_args.
if "%~1" == "/sort_args" goto :sort_args

rem Store all arguments in a named variable.
set args=%*

rem Process sorted arguments.
for /f "delims=" %%A in ('cmd /c "%~f0" /sort_args') do (
    echo %%A
)
exit /b 0


:sort_args

rem Abort if no arguments.
if not defined args exit /b 0

rem Sort arguments.
(for %%A in (%args%) do @echo %%A) | sort
exit /b 0

If the original arguments do not have /sort_args as an argument, then this will store the arguments in args .如果原始 arguments 没有/sort_args作为参数,那么这会将 arguments 存储在args中。 The for /f loop will run this code again to sort the original arguments and echo the arguments back to the for /f loop for processing. for /f循环将再次运行此代码以对原始 arguments 进行sort ,并将 arguments 回显到for /f循环进行处理。

Can change /sort_args to something more unique if wanted.如果需要,可以将/sort_args更改为更独特的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM