[batch] Wildcard match in for-loop werkt niet

Pagina: 1
Acties:

  • _Thanatos_
  • Registratie: Januari 2001
  • Laatst online: 05-09 14:39

_Thanatos_

Ja, en kaal

Topicstarter
Ik heb een batch file gemaakt, en daar zit dit in:
code:
1
2
3
for /r %%f in (*.jpg) do (
  echo %%~xf
)


Werkt. Alleen, eigenlijk niet. Deze for-loop matcht ook *.jpg1 en *.jpgblaat en alles wat de extensie jpg plus nog wat heeft. Dus eigenlijk is dit equivalent aan *.jpg*. Dit probleem geldt niét als ik match op bijv *.in, de for-loop werkt dan alléén op *.in en niet op *.in1.

Waarom is dit, en hoe zorg ik ervoor dat dit alléén, en dus ALLEEN *.jpg matcht, en niet *.jpg*?

日本!🎌


  • Raven
  • Registratie: November 2004
  • Niet online

Raven

Marion Raven fan

Eerste wat in mij opkomt: quotes om *.jpg? Dus "*.jpg"

edit:
En wat leesvoer over vergelijkbare gevallen:
http://superuser.com/ques...perate-on-xyz-but-not-xyz
http://stackoverflow.com/...-dir-txt-return-txtf-also
http://stackoverflow.com/...cards-extending-extension
http://stackoverflow.com/...eted-using-command-prompt

[ Voor 126% gewijzigd door Raven op 14-08-2014 11:25 ]

After the first glass you see things as you wish they were. After the second you see things as they are not. Finally you see things as they really are, and that is the most horrible thing in the world...

Oscar Wilde


  • _Thanatos_
  • Registratie: Januari 2001
  • Laatst online: 05-09 14:39

_Thanatos_

Ja, en kaal

Topicstarter
Quots of geen quotes maakt niet uit...

Maargoed, het komt dus neer op een tweede (en derde, vierde, vijfde, etc - voor extra extensies) check, a.k.a Microsoft Moeilijk Doen.

iig bedankt voor de input :)

Wel nog een enigzins gerelateerd probleem: de FOR-loop returnt bestanden met een uitroepteken zónder het uitroepteken. Dat wordt gewoon weggeflikkerd. Als ik %%f echo, is een evt uitroepteken gewoon *weg*... Hoe? Waarom? Kan dit ook gewoon... werken?

[ Voor 37% gewijzigd door _Thanatos_ op 14-08-2014 12:22 ]

日本!🎌


  • Raven
  • Registratie: November 2004
  • Niet online

Raven

Marion Raven fan

Mbt het uitroepteken: http://www.computerhope.com/forum/index.php?topic=119206.0 , is weliswaar een andere situatie, maar denk dat dit van toepassing is:
The string variable for each line is not being created correctly because with delayed expansion enabled, exclamation marks are variable delimiters and thus are ignored along with everything between them. Batch scripts get terribly fiddly when special characters ("poison characters" are embedded in strings to be processed. The worst is the ampersand but parentheses and percent signs are among the others.
edit: En nog meer leesvoer: Handling ! in filenames with SETLOCAL ENABLEDELAYEDEXPANSION

[ Voor 12% gewijzigd door Raven op 14-08-2014 12:52 ]

After the first glass you see things as you wish they were. After the second you see things as they are not. Finally you see things as they really are, and that is the most horrible thing in the world...

Oscar Wilde