简体   繁体   English

根据部分文件名批量创建文件夹并将文件移动到文件夹

[英]Batch create folder based on partial file name and move files to folder

I have a series of .wav files with similar file names.我有一系列具有相似文件名的 .wav 文件。 Each file has a first and last name followed by the date and a number.每个文件都有一个名字和姓氏,后跟日期和一个数字。 I would like to create a series of files based on the first and last name and then move the files to the matching file path.我想根据名字和姓氏创建一系列文件,然后将文件移动到匹配的文件路径。

Example:例子:

John_Doe_1-6-6-2021 15-23_123453245.wav
John_Doe_1-6-6-2021 15-23_12345874.wav
John_Doe_1-6-6-2021 15-23_1239964.wav

Mary_Walker_1-6-6-2021 15-23_123453245.wav
Mary_Walker_1-6-6-2021 15-23_1778941.wav
Mary_Walker_1-6-6-2021 15-23_8741556899.wav

I would like those files to be organized similar to the following:我希望这些文件的组织方式类似于以下内容:

SourceDirectory
 |> John_Doe_1
     |> John_Doe_1-6-6-2021 15-23_123453245.wav
     |> John_Doe_1-6-6-2021 15-23_12345874.wav
     |> John_Doe_1-6-6-2021 15-23_1239964.wav

 |> Mary_Walker_1
   |> Mary_Walker_1-6-6-2021 15-23_123453245.wav
   |> Mary_Walker_1-6-6-2021 15-23_1778941.wav
   |> Mary_Walker_1-6-6-2021 15-23_8741556899.wav

At the moment I have this script.目前我有这个脚本。 The script will create a folder based on the First Name and moves the files there (Which is great), the only issue is I need the first name, last name and the 1 at the end.该脚本将根据名字创建一个文件夹并将文件移动到那里(这很棒),唯一的问题是我需要名字、姓氏和最后的 1。 So the Folder should be like John Doe 1 not just John or John Doe .所以文件夹应该像John Doe 1而不仅仅是JohnJohn Doe

@echo off
SETLOCAL
SET "sourcedir=C:\Users\JohnUser\Desktop\Test\"
PUSHD %sourcedir%
FOR /f "tokens=1*" %%a IN (
 'dir /b /a-d "* *_*-* *.*"'
 ) DO (  
 MD %%a
MOVE "%%a %%b" .\%%a\
)
POPD
GOTO :EOF

pause

Here's a quick example using the - character as the delimiter, Delims , to perform the fiilename string split.这是一个使用-字符作为分隔符Delims来执行文件名字符串拆分的快速示例。 (You could use Tokens=1 , but as that is the default, I have left it out) : (您可以使用Tokens=1 ,但由于这是默认设置,我已将其省略)

@Echo Off
SetLocal EnableExtensions
Set "SourceDir=%UserProfile%\Desktop\Test"
For /F "Delims=" %%G In (
    '%SystemRoot%\System32\where.exe "%SourceDir%":"?*-?*-?*-???? ??-??_?*.wav"'
) Do For /F "Delims=-" %%H In ("%%~nG") Do (
    %SystemRoot%\System32\Robocopy.exe "%SourceDir%" "%SourceDir%\%%H" "%%~nxG" /Mov 1>NUL
)

To understand how any command works, open a Command Prompt window, type Command /?要了解任何命令的工作原理,请打开命令提示符窗口,键入Command /? . . For example for /?例如for /? , where /? where /? , robocopy /? , robocopy /? . .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 批量创建基于部分文件名的文件夹并将文件移动到该文件夹​​中 - Batch create folders based on part of file name and move files into that folder 根据部分文件名创建文件夹并将文件移动到创建的文件夹中 - Create Folders based on part of file name and move files into the created folder 批处理文件以创建目录并根据部分文件名移动文件 - Batch file to create directories and move files based on partial file names 将批处理文件移动到具有相似名称的文件夹 - Move Batch files to folder with similar name 批处理命令基于文件名创建文件夹并将文件/文件夹移动到创建的文件夹 - Batch command to create folder based on filename and move files/folders to created folder 根据文件名批量创建文件夹,并将多个相关文件移动到创建的文件夹中 - Batch Create a Folder Based on Filename, and Move Multiple Related Files to The Created Folder 批处理文件以重命名多个文件并移至文件夹 - Batch File to rename multiple files and move to folder 批处理文件可将一个文件夹中的文件和文件夹移动到另一个文件夹 - Batch file to move files and folders in a folder to another folder 为每个文件名创建文件夹并移动文件 - Create folder for each file name and move the file 将文件夹名称附加到文件名并使用DOS批处理移动文件 - Append folder name to file name and move file using DOS batch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM