Batch Move files to sub-directory from list.txt
If you have a long list of files that you need to move to a specific sub-directory, it can be a tedious task to do it manually. Luckily, there is a way to automate this process using a simple script and a text file. In this article, we will guide you through the steps of batch moving files to a sub-directory from a list.txt file.
Step 1: Create a text file
The first step is to create a text file that contains the list of files you want to move. You can use any text editor to create this file. Each file should be on a new line. For example:
file1.txt
file2.txt
file3.txt
Save this text file with a name like "list.txt" and remember the location where you saved it.
Step 2: Create a batch file
Next, we need to create a batch file that will read the list.txt file and move the files to the desired sub-directory. Open a new text file and paste the following code:
@echo off
set source_dir=C:\path\to\files
set target_dir=C:\path\to\sub-directory
for /f "delims=" %%i in (list.txt) do (
move "%source_dir%\%%i" "%target_dir%\"
)
echo All files moved successfully.
pause
Make sure to replace "C:\path\to\files" with the actual path to the directory where your files are located, and "C:\path\to\sub-directory" with the path to the sub-directory where you want to move the files. Save this file with a .bat extension, for example, "move_files.bat".
Step 3: Run the batch file
Now that we have the batch file ready, we can run it to move the files. Double-click on the batch file to execute it. A command prompt window will open, and you will see the progress as the files are moved one by one.
Once all the files have been moved, you will see the message "All files moved successfully." Press any key to close the command prompt window.
Conclusion
Batch moving files to a sub-directory from a list.txt file can save you a lot of time and effort, especially when dealing with a large number of files. By following the steps outlined in this article, you can easily automate this process and streamline your file management tasks.
References
| Source | Link |
|---|---|
| Microsoft Docs | https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/move |