How to automate this: Download a file to custom folder or another file path or another directory

Hey There,
I am downloading a file that is by default downloading and getting stored in C: drive downloaded folder. But I want to download that file to another folder which is in my D: drive.

Please suggest what to do and how to do it. Thanks in advance.

I can think of two options:

  • Use XTYPE to enter a new download path in the download dialog

  • Or (easier): Download first to C, then use XRUN to call e. g. a batch file to move the file.

Thank you @ulrich This helped me a lot. Now my macro running like a pro. could you please help me for other two questions which I have posted?

If anyone looking for a solution to this problem. Here is the solution to what you have to do.

The below code will identify the most recent file created or downloaded in your source path and will move the file to the destination path. Only the sourcePath and destinationPath you have to change in the below code.

@echo off
set “sourcePath= Ex: C:\Users\biswa\Downloads”
set “destinationPath= Ex: D:\RPA\Udemy”

rem Get the most recently created or downloaded file
for /f “delims=” %%a in (‘dir /b /a-d /o-d /tw “%sourcePath%”’) do (
set “mostRecentFile=%%a”
goto :MoveFile
)

:MoveFile
if defined mostRecentFile (
rem Create the destination folder if it doesn’t exist
if not exist “%destinationPath%” mkdir “%destinationPath%”

rem Move the most recently created or downloaded file to the destination
move "%sourcePath%\%mostRecentFile%" "%destinationPath%"

echo File "%mostRecentFile%" moved successfully to "%destinationPath%"

) else (
echo No files found in “%sourcePath%”
)

Copy the above code and paste it into a notepad. Save the file as “.bat” with the File type “All Files”

Then user XRun to run the .bat file. Below is a sample example.
Command: XRun
Target: Ex: D:\RPA\Udemy\MoveFileBatFile.bat

1 Like