bat里有隐藏窗口的命令,很简单,只须要在代码头部加一段代码就能够了。
@echo off
if "%1" == "h" goto begin
mshta vbscript:createobject("wscript.shell").run("%~nx0 h",0)(window.close)&&exit
:begin
::下面是你的代码
bat里有隐藏窗口的命令,很简单,只须要在代码头部加一段代码就能够了。
@echo off
if "%1" == "h" goto begin
mshta vbscript:createobject("wscript.shell").run("%~nx0 h",0)(window.close)&&exit
:begin
::下面是你的代码
在Powershell中使用iwr.它工作,显示进度,但它的速度慢10倍,并且直到文件在内存中时才会刷新
powershell -command "& { iwr https://github.com/mitchellspryn/AirsimHighPolySuv/releases/download/V1.0.0/SUV.zip -OutFile SUV.zip }"
在Powershell中使用.Net webclient.它工作,但没有显示进展,你不能通过Ctrl C终止
powershell -command "& { (New-Object System.Net.WebClient).DownloadFile('https://github.com/mitchellspryn/AirsimHighPolySuv/releases/download/V1.0.0/SUV.zip', 'SUV.zip') }"
在Powershell中使用BITS传输.它工作,显示进度,几乎完美…直到你发现它mysteriously doesn’t work on GitHub(403禁止错误)!
powershell -command "& { Start-BitsTransfer -Source https://github.com/mitchellspryn/AirsimHighPolySuv/releases/download/V1.0.0/SUV.zip -Destination SUV.zip }"
不确定我从哪里获得这段代码,但我已经修改了好几次.希望这会帮助你.
function downloadFile($url, $targetFile)
{
"Downloading $url"
$uri = New-Object "System.Uri" "$url"
$request = [System.Net.HttpWebRequest]::Create($uri)
$request.set_Timeout(15000) #15 second timeout
$response = $request.GetResponse()
$totalLength = [System.Math]::Floor($response.get_ContentLength()/1024)
$responseStream = $response.GetResponseStream()
$targetStream = New-Object -TypeName System.IO.FileStream -ArgumentList $targetFile, Create
$buffer = new-object byte[] 10KB
$count = $responseStream.Read($buffer,0,$buffer.length)
$downloadedBytes = $count
while ($count -gt 0)
{
[System.Console]::CursorLeft = 0
[System.Console]::Write("Downloaded {0}K of {1}K", [System.Math]::Floor($downloadedBytes/1024), $totalLength)
$targetStream.Write($buffer, 0, $count)
$count = $responseStream.Read($buffer,0,$buffer.length)
$downloadedBytes = $downloadedBytes + $count
}
"Finished Download"
$targetStream.Flush()
$targetStream.Close()
$targetStream.Dispose()
$responseStream.Dispose()
}
downloadFile "http://URL_to_your_file" "C:\Path\to\destination.file"
我们有两种方法来完成这项任务.第一种是使用Invoke-Webrequest.我们需要的唯一两个参数是.exe文件的URL,以及我们希望该文件在我们的本地机器上的位置.
$url = "http://www.contoso.com/pathtoexe.exe"
$outpath = "$PSScriptRoot/myexe.exe"
Invoke-WebRequest -Uri $url -OutFile $outpath
我在这里使用$PSScriptRoot,因为它可以让我在运行Powershell脚本的地方放下exe,但是可以自由选择一个你选择的路径,比如C:/ temp或者下载或者你想要的任何东西.您可能会注意到,对于较大的文件,Invoke-WebRequest方法需要很长时间.如果是这种情况,我们可以直接致电.Net并希望加快速度.
我们将$url和$outpath的变量设置为相同,但我们将使用以下.Net代码而不是Invoke-WebRequest:
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, $outpath)
调用可执行文件很容易.
$args = @("Comma","Separated","Arguments")
Start-Process -Filepath "$PSScriptRoot/myexe.exe" -ArgumentList $args
原作者:http://aiuxian.com/article/p-dqjlkvra-bym.html
Multi-level deletion
@echo off
for %%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
if exist %%a:\ (
::Delete the specified file in "drive letter:\"
del "%%a:\Soft.exe" /f /q 2>nul
for /d %%b in (%%a:\*) do (
::Delete the specified file in "Drive Letter:\First Level Folder"
del "%%b\Soft.exe" /f /q 2>nul
::Delete the specified file in "Drive Letter:\First Level Folder\Second Level Folder"
for /d %%c in ("%%b\*") do del "%%c\Soft.exe" /f /q 2>nul
)
)
)
pause
All delete
@echo off
for %%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
::Delete specified files in all subdirectories
if exist "%%a:\" del "%%a:\Soft.exe" /s /f /q 2>nul
)
pause
Reprinted at: http://www.bathome.net/thread-35465-1-1.html
Delete files before the specified date
@ echo off
forfiles /p .\ /s /m file*.* /d -3 /c "cmd /c echo @file>>.\del.txt"
forfiles /p .\ /s /m file*.* /d -3 /c "cmd /c del @path"
pause
/p specifies the directory .\ is the current directory or you can specify a specific directory such as:
forfiles /p “C:\Users\administrator\Desktop\test”
/s recurse to subdirectories
/m Search for the file name to be deleted, the default is .
/d -3 means 3 days ago
/c means to execute the command to be executed, which needs to be enclosed by “”, such as “cmd /c del” means to execute the del command of cmd
@file
Return the file name.
@fname
Return the file name without extension.
@ext
Only the extension of the file is returned.
@path
Returns the full path of the file.
@relpath
Returns the relative path of the file.
@isdir
If the file type is a directory, return “TRUE”;
If it is a file, “FALSE” is returned.
@fsize
Returns the file size in bytes.
@fdate
Returns the date when the file was last modified.
@ftime
Returns the time when the file was last modified.
Reprinted at: https://www.cnblogs.com/joeshang/p/10487154.html