Select if exist 命令中的两个文件

Select two files in the if exist command

事实是我是编程新手。所以如果你能帮助我,我会很高兴。 我需要在 "if exits" 命令中 select 两件事,即两个文件或其中之一,以下命令适用。 这是代码:

if exist *.mp3 *.wma *.wav goto music
if exist *.mp4 *.mov goto video
if exist *.docx *.txt *.pdf goto document
if exist *.jpg *.png goto image
goto end
:music
md Music
move *.mp3 Music
move *.wma Music
move *.wav Music
if exist *.mp4 *.mov goto video
if exist *.docx *.txt *.pdf goto document
if exist *.jpg *.png goto image
goto end
:video
md Video
move *.mp4 Video
move *.mov Video
if exist *.docx *.txt *.pdf goto document
if exist *.jpg *.png goto image
goto end
:document
md Documents
move *.docx Documents
move *.txt Documents
move *.pdf Documents
if exist *.jpg *.png goto image
goto end
:image
md Pictures
move *.jpg Pictures
move *.png Pictures
goto end
:end
exit

找了没找到,试了各种办法也没成功。 谢谢!

您可以使用循环来迭代值:

for %%a in (mp3 wma wav) do if exist *.%%a goto music

为了提高可读性,您甚至可以定义一个宏并重复使用它们:

::::: marco ::::::::::
set "if_one_of=for %%a in ("
set "exist=) do if exist *.%%a"
:::::::::::::::::::::::

%if_one_of% mp3 wma wav %exist% goto music

更多关于 FOR

您可以用以下四行替换整个代码:

for %%a in (mp3 wma wav) do if exist *.%%a md music 2>nul & move *.%%a music\
for %%a in (mp4 mov) do if exist *.%%a md video 2>nul & move *.%%a video\
for %%a in (docx txt pdf) do if exist *.%%a md documents 2>nul & move *.%%a documents\
for %%a in (jpg png) do if exist *.%%a md pictures 2>nul & move *.%%a pictures\