2017-09-14 9 views
0

私は現在、複数のユーザーのダウンロードを削除するバッチファイルを作成しています。私は、たとえば、拡張子の名前を持つフォルダを取得(ccomley.V2)に立ち往生しています。拡張名を持つ複数のフォルダを削除するにはどうすればよいですか? (バッチファイル)

プロファイルは約172あり、私はそれらをすべて別のコマンドラインで実行できますが、1行で削除する方が簡単ですか?

現在の行のバッチファイル、

color 2 
del "C:\logs\student_deletion.log" 
cls 
@echo off 
@setlocal 

set start=%time% 

:: Runs your command 
cmd /c %* 

set end=%time% 
set options="tokens=1-4 delims=:.," 
for /f %options% %%a in ("%start%") do set start_h=%%a&set /a start_m=100%%b %% 100&set /a start_s=100%%c %% 100&set /a start_ms=100%%d %% 100 
for /f %options% %%a in ("%end%") do set end_h=%%a&set /a end_m=100%%b %% 100&set /a end_s=100%%c %% 100&set /a end_ms=100%%d %% 100 

set /a hours=%end_h%-%start_h% 
set /a mins=%end_m%-%start_m% 
set /a secs=%end_s%-%start_s% 
set /a ms=%end_ms%-%start_ms% 
if %ms% lss 0 set /a secs = %secs% - 1 & set /a ms = 100%ms% 
if %secs% lss 0 set /a mins = %mins% - 1 & set /a secs = 60%secs% 
if %mins% lss 0 set /a hours = %hours% - 1 & set /a mins = 60%mins% 
if %hours% lss 0 set /a hours = 24%hours% 
if 1%ms% lss 100 set ms=0%ms% 

:: Mission accomplished 
set /a totalsecs = %hours%*3600 + %mins%*60 + %secs% 

cd /d "c:\users" 
echo Date: %date% Time: %time% >> C:\logs\student_deletion.log 
echo. >> C:\logs\student_deletion.log 

dir \\SRV-FILES01\IJ_StudentsW$\Profiles\ccomley.V2\downloads >> C:\logs\student_deletion.log 
for /d %%a in (*) do rd /s /q "\\SRV-FILES01\IJ_StudentsW$\Profiles\ccomley.V2\downloads" >>nul 2>>&1 
@echo Successfully deleted ccomley downloads! (%totalsecs%.%ms%s total) to delete their downloads 
echo ccomley took, (%totalsecs%.%ms%s total) to delete their downloads >> C:\logs\student_deletion.log 
echo. >> C:\logs\student_deletion.log 

dir \\SRV-FILES01\IJ_StudentsW$\Profiles\anotheraccount.V2\downloads >> C:\logs\student_deletion.log 
for /d %%a in (*) do rd /s /q "\\SRV-FILES01\IJ_StudentsW$\Profiles\anotheraccount.V2\downloads" >>nul 2>>&1 
@echo Successfully deleted anotheraccount downloads! (%totalsecs%.%ms%s total) to delete their downloads 
echo anotheraccount took, (%totalsecs%.%ms%s total) to delete their downloads >> C:\logs\student_deletion.log 
echo. >> C:\logs\student_deletion.log 

は、あなたが私を助けることを願って! (サイドノート。私は、*やって試してみました、)

(それはそこに個人情報を持っている全体のバッチファイルを表示することはできません。)このブロックを繰り返し実行する必要が

答えて

0
dir \\SRV-FILES01\IJ_StudentsW$\Profiles\ccomley.V2\downloads >> C:\logs\student_deletion.log 
for /d %%a in (*) do rd /s /q "\\SRV-FILES01\IJ_StudentsW$\Profiles\ccomley.V2\downloads" >>nul 2>>&1 
@echo Successfully deleted ccomley downloads! (%totalsecs%.%ms%s total) to delete their downloads 
echo ccomley took, (%totalsecs%.%ms%s total) to delete their downloads >> C:\logs\student_deletion.log 
echo. >> C:\logs\student_deletion.log 

固定テキストccomley[.v2]が変数に置き換えられています。

簡単な方法は、パラメータとして必要な名前を渡すサブルーチンとしてcallです。

:sub 
setlocal 
set "name=%%~n1"&set "ext=%%~x1" 
:: if no ext, abandon ship. 
if not defined ext goto :eof 
:: otherwise, execute the block with `%~1`, `%name%` and `%ext%' as required. 

ユーザーにfred.bloggsのファイルを削除するzap1user fred.bloggsを実行することができるようにこれは、内部サブルーチン、または好ましくは独立したバッチである可能性があります。

次のステップは、タイミングをサブルーチンに含めることです。 setlocalの後にstartfor...rd...endと設定した後、計算を行ってレポートフィールドを生成します。サブ手順のsetlocalのため、これはではなく、は、startおよびend回のメインプロシージャに影響します。

最終、単に削除する名前を生成して行わcall

for /d %%x in ("\\SRV-FILES01\IJ_StudentsW$\Profiles\*") do call zap1user "%%x" 

、すべてを経由してサブルーチンにそれらの名前を渡すために\\SRV-FILES01\IJ_StudentsW$\Profilesディレクトリにfor /dを使用!

(よくあることですが、経過時間ルーチンを2つのパラメータ、開始時間と終了時間、および経過時間を計算する別の補助バッチにすることもできます。

+0

おかげさまで、それが簡単なことに気付かなかったのです! –

関連する問題