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.
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