2016-07-19 4 views
1

私は約2000個のjpgファイルをフォルダに持っており、それぞれ同じ名前のフォルダを作る必要があります。 jpgは必ずしも同じフォルダにある必要はありません。私はバッチスクリプトに慣れていないが、それは非常に単純な操作のように思えた。これは私が今までに持っているものです:Windowsのディレクトリをバッチスクリプトにする

for %%i in (*) do md %%i 

私はそれを実行すると、サブディレクトリまたはファイルが既に存在すると言います。同じ名前のファイルがすでに存在していても、ディレクトリを作成するにはどうすればよいですか?

また、最後の100個のファイルに対してのみループするように見えます。 〜2000のためにそれをどのように稼働させるのですか?

+0

同じ名前のファイルとディレクトリを同じ場所に置くことはできません。これはWindowsでは不可能です。 'image01.jpg'というファイルがあるとすると、関連するディレクトリを' image01'( '.jpg'サフィックスなし)とするべきでしょうか? – aschipfl

+0

'do MD %%〜dpi' for /?のヘルプの終わりを見てください。 –

+0

@aschipfl、そうですよ!私は、ディレクトリ名に.jpgサフィックスを付けたくありません。 – ldpelegr

答えて

0

あなたはそのような何か試すことができます:25コマンドラインで

for /? 

を呼び出す

:20 @ 20/07/2016に

@echo off 
set "ext=*.jpg" 
for %%i in ("%ext%") do ( 
    if not exist "%%~ni" MD "%%~ni" 
) 
pause 

編集をこの構文についての助けを与えます(FOR以外でも使用できますが、これはヘルプが見つかる場所です)。

さらに、可変参照のFOR の置換が強化されました。 %IおよびPATHが 他に置き換えることができる上記の例では

%~dpI  - expands %I to a drive letter and path only 
%~nxI  - expands %I to a file name and extension only 
%~fsI  - expands %I to a full path name with short names only 
%~dp$PATH:I - searches the directories listed in the PATH 
       environment variable for %I and expands to the 
       drive letter and path of the first one found. 
%~ftzaI  - expands %I to a DIR like output line 

:修飾子は 化合物の結果を得るために組み合わせることができる

%~I   - expands %I removing any surrounding quotes (") 
%~fI  - expands %I to a fully qualified path name 
%~dI  - expands %I to a drive letter only 
%~pI  - expands %I to a path only 
%~nI  - expands %I to a file name only 
%~xI  - expands %I to a file extension only 
%~sI  - expanded path contains short names only 
%~aI  - expands %I to file attributes of file 
%~tI  - expands %I to date/time of file 
%~zI  - expands %I to size of file 
%~$PATH:I - searches the directories listed in the PATH 
       environment variable and expands %I to the 
       fully qualified name of the first one found. 
       If the environment variable name is not 
       defined or the file is not found by the 
       search, then this modifier expands to the 
       empty string 

: あなたは今、次のオプション の構文を使用することができます有効な値。 %〜構文は有効な FOR変数名で終了します。ピックアップ大文字の %Iのような変数名は、 をより読みやすくし、 修飾子との混乱を避けます。これらの修飾子は、大文字と小文字は区別されません。 。

ありますが、パスに「フルパス名」のf、ドライブ文字のためdpのように使用することができます異なる文字があり、それらを組み合わせることができます。 %~はそれぞれのシーケンスの始まりであり、数字Iはパラメータ%I(ここで、%0は、想定したとおりにバッチファイルの完全な名前です)で動作することを示します。

+0

これは私がそれを必要とした方法で正確に機能しました!ありがとうございました。あなたは '%%〜ni'が何をしているのかを私に説明できますか? – ldpelegr

+0

@Idpelegr私の編集をチェックして、 '%%〜ni'が何であるかを理解し、この回答とupvoteを受け入れることを忘れないでください。がんばろう ! – Hackoo

関連する問題