【问题标题】:Downloading file from URL using start chrome使用 start chrome 从 URL 下载文件
【发布时间】:2018-09-22 11:28:48
【问题描述】:

我有一个批处理文件,它打开一个 URL 以下载 csv 文件,然后我需要移动该 csv 表单下载文件夹并将其重命名为另一个。

我拥有的是:

@echo off

SET CCDIR=C:\Users\(username)\Desktop
SET LOADDIR=C:\Users\(username)\Downloads

ECHO ***************************************************************************
ECHO  Downloading the file
ECHO ***************************************************************************

start chrome (URL string)

:NEXT

ECHO ***************************************************************************
ECHO  Move CSV file from Downloads folder to Desktop
ECHO ***************************************************************************

move %LOADDIR%\*(file string)* %CCDIR%
ren %CCDIR%\*(file string)* (new file name)

我想在同一个 bat 中执行所有操作,但只有 start chrome 正在工作,bat 忽略了 move 和 ren。

我该怎么做?

【问题讨论】:

  • 使用 curl、wget 或 powershell Invoke-Webrequest 进行下载。在尝试移动和重命名之前,您的(相当混乱的)批次不会等待下载完成。
  • 感谢您的快速回答 LotPings,那么您的意思是在批处理中使用 wget 命令而不是“start chrome”?那会产生同样的效果吗?
  • 是的,wget 是一个无需打开网络浏览器即可从 Internet 下载文件的程序。这将使您的脚本明显更快、更便携。
  • wgetcurl 是第三方应用程序,后者也是very lastest Windows 10 version 的一部分。 Powershell 自 Windows 7 起包含并具有类似的 cmdlet Invoke-Webrequest
  • 您可以使用certutil 命令下载文件。 Take a look at this example

标签: batch-file


【解决方案1】:

根据我的评论,你可以试试这个例子下载Certuil command的文件

@echo off
Title Downloading a file using Certutil Command
Mode 70,5 & color 0A
SET CCDIR=%userprofile%\Desktop
SET LOADDIR=%userprofile%\Downloads
set "url=https://download.sysinternals.com/files/PSTools.zip"
echo(
ECHO   ******************************************************************
ECHO          Please wait a while ... Downloading the file ...
ECHO   ******************************************************************
Call :download %url% %LOADDIR%
Rem Moving the downloaded file from the folder Downloads to Desktop
move /Y "%file%" "%CCDIR%\">nul
Rem Open the desktop folder with explorer
Explorer "%CCDIR%\"
goto :eof
::--------------------------------------------
:Download <Url> <File>
Set url="%~1"
Set file=%2\%~nx1
certutil.exe -urlcache -split -f %url% %file%>nul
Rem Deleting cache
certutil -urlcache "%~1" delete>nul
Rem Check referenced urlcache is deleted
certutil.exe -v -urlcache -split "%~1">nul
exit /b
::--------------------------------------------

【讨论】:

  • Hackoo,感谢您的建议,我会尽快尝试,问候。
猜你喜欢
  • 2015-09-12
  • 2017-01-31
  • 1970-01-01
  • 2014-12-23
  • 2015-10-28
  • 2013-09-16
  • 2021-12-16
  • 2017-01-23
相关资源
最近更新 更多