0

I have a batch file that opens a URL to download a csv file, then I need to move and then rename that csv form downloads folder to other one.

What I have is:

@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) 

I want to execute it all in the same bat, but just the start chrome is working, the bat is ignoring the move and ren.

How can I do that?

6
  • 1
    Use curl, wget or powershell Invoke-Webrequest to do the download. Your (pretty scrambledd) batch won't wait for the download to finish before trying to move and rename it. Commented Sep 22, 2018 at 11:47
  • Thanks for your quick answer LotPings, so what do you mean is use wget command in the batch instead of "start chrome"? That will make the same effect? Commented Sep 22, 2018 at 12:01
  • Yes, wget is a program meant for downloading files from the internet without needing to open a web browser. This will make your script significantly faster and more portable. Commented Sep 22, 2018 at 12:40
  • 2
    wget and curl are 3rd party apps where the latter is also part of the very lastest Windows 10 version. Powershell is contained since Windows 7 and has the similar cmdlet Invoke-Webrequest Commented Sep 22, 2018 at 13:52
  • 1
    You can download files with certutil command. Take a look at this example Commented Sep 22, 2018 at 17:54

1 Answer 1

2

Based on my comment, you can give a try for this example to download a file with 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 ::-------------------------------------------- 
Sign up to request clarification or add additional context in comments.

1 Comment

Hackoo, thanks for your advise, I will try this shortly, Regards.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.