Home > Common Problem > How to sort and move files by extension on Windows

How to sort and move files by extension on Windows

WBOY
Release: 2023-05-11 23:22:13
forward
1875 people have browsed it

Sometimes, your folders can get so cluttered with all the file types in the world. A prime example is the Downloads folder, where you download and download and never care about organizing. Wouldn't it be great if you double-clicked somewhere and automatically had all your messy files neatly sorted and moved into their respective folders based on their respective extensions? So, get ready to embrace the beautiful! We are here to guide you on how to accomplish this trick with the help of a simple batch script.

Step 1: Navigate to the parent folder that contains all the files that need to be sorted and moved. This can be any folder of your choice, including the "Downloads" folder.

In the example below, in my parent folder I have a number of files with various extensions.

如何在 Windows 上根据扩展名对文件进行排序和移动

Step 2: Next, right-click the blank area and click "New" Options and click "Text Document" Options.

如何在 Windows 上根据扩展名对文件进行排序和移动

Step 3: You now need to double-click on the new text document you just created. This will open the newly created text document in Notepad for editing.

如何在 Windows 上根据扩展名对文件进行排序和移动

Step 4: When Notepad starts to open, copy and paste the following script onto it.

@echo 关闭rem thegeekpage.com对于 (".\*") 中的 %%a 执行 (      如果 "%%~xa" NEQ "" 如果 "%%~dpxa" NEQ "%~dpx0" (            如果不存在 "%%~xa" mkdir "%%~xa" (                   移动 "%%a" "%%~dpa%%~xa\"            )       ))
Copy after login

如何在 Windows 上根据扩展名对文件进行排序和移动After copying the above script,

press the CTRL S key at the same time to save the file.

After saving, you can close the file.

Explanation:

This script iterates through all files in the parent folder. The batch script we created is ignored, sorting and moving are not considered.
  1. The script gets each file and checks its extension.
  2. The script then checks to see if a folder with the same name as the current file's extension exists in the parent folder. If the folder does not exist, create it.
  3. Once a folder is created or found to exist, the file will be moved to it.
  4. Repeat steps 2 to 5 until all files have been checked and moved as necessary.
Step 5

: After that, go back to the parent folder, click on the saved text file and press the F2 keyRename . You can provide any name according to your choice, but make sure to specify the extension of the file as bat, after . (dot). Click elsewhere when finished naming. Note:

Having the extension as bat is the most important part

.

如何在 Windows 上根据扩展名对文件进行排序和移动

Step 6

: When you click elsewhere, you will see the following Rename confirmation window. Click the Yes button to continue.

如何在 Windows 上根据扩展名对文件进行排序和移动

Step 7

: Next, you can double-click the batch file to execute it. Be careful with this step, it cannot be recovered.

如何在 Windows 上根据扩展名对文件进行排序和移动

Step 8

: Viola! You can now see that all the files in the parent folder are now neatly sorted and moved to their respective folders based on their extensions. enjoy!

The above is the detailed content of How to sort and move files by extension on Windows. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yundongfang.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template