Batch File Sorting organizer

Source: Internet
Author: User

CopyCode The Code is as follows: @ echo off
Title file category Organizer-test

:: ========================================================== ========================================================== ===
: Purpose:
::
: Sorts the files in the current directory and all its subdirectories.
::
: Sorting result:
::
: In the current directory and Its subdirectories, name the folder name as the file type in the folder.
: Create folders in the directory, such as EXE files and rarfiles. Move different types of files
: The corresponding folder.
: If a new file is added later and the script is run again, if the corresponding folder already exists at the location,
: Save the newly added file to this folder. If no corresponding folder exists, create a folder to save it.
: This file.
::
: Functions to be implemented in the next version:
::
: ① Organize subdirectories with the current directory as the starting point and the specified layer depth;
: ② Sort out files of a specified type.
::
: Update history:
::
: 2006-12-16
::
: Added the function to stop sorting classified files. This is V1.1;
::
: 2006-12-15
::
: You can only sort out different types of files in the current directory, and write
: Code for operations on different types of files. This is V1.0;
:: ========================================================== ========================================================== ===

Set "file_route = % Cd %"
For/F "delims =" % I in ('dir/a-d/B/S/Oe ') Do (
Set "nx_name = % ~ Nxi"
Call: build_dir % ~ Xi "% ~ DPI"
Set file_type = % ~ XI
Set "file_route = % ~ DPI"
)
Goto: EOF

Rem ======= create folders by file type ======
: Build_dir
Set types = % 1
Set route = % 2
Set types = % types :~ 1%
Set "route = % route :~ 1,-1%"
Set "cd_name = % route :~ 0,-1%"

Rem ======= get the directory name of the file ======
: Get_cd_name
Set "cd_name_tmp = % cd_name: \ = %"
Set "cd_name = % cd_name: * \ = %"
If not "% cd_name %" = "% cd_name_tmp %" Goto get_cd_name

: Compare the file type name and directory name to determine which files have been sorted
If "% cd_name %" = "% types % file" Goto: EOF

: Determines whether the file location has changed.
If % 2 = "% file_route %" (set chang_dir =) else set chang_dir = Yes & set file_type =

: Determines whether the file to be processed is a batch file.
If "% route % nx_name %" = "% ~ F0 "(set file_self = yes) else set file_self =

: Determines whether the file type has changed.
If "% 1" = "% file_type %" (set same_type = yes) else set same_type =

If not defined chang_dir (
If not defined file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.