将所有类型的文件移动到 Windows 7 中的新文件夹

Der*_*rek 5 windows file-management file-transfer command-line

任何人都可以帮助解决这个问题。

我在商店里到处都是 mp3 文件,因此有很多重复文件。

我需要的是一个命令行函数,它将所有 mp3 类型的文件移动到一个新文件夹。我不担心新文件夹上的文件结构是否保留。

例如,我可以使用 copy c:*.mp3 /sc:\mp3 轻松复制,但是由于我拥有的文件数量太多,我复制它们时会耗尽磁盘空间,因此需要移动。

谢谢

Gir*_*iri 6

从您拥有 mp3 文件的顶级文件夹尝试此命令。

forfiles /M *.mp3 /C "cmd /c move @file C:\music"
Run Code Online (Sandbox Code Playgroud)

请注意,如果您有重名的文件,将所有文件移动到一个文件夹中是不正确的做法。它会导致数据丢失。

还有一种方法可以使用/S标志移动子目录中与条件匹配的所有文件:

forfiles /S /M *mp3 /C "cmd /c move @files C:\music
Run Code Online (Sandbox Code Playgroud)

这将递归搜索当前目录中的所有文件夹

参考:Forfiles windows 命令


Dav*_*ave 0

我认为这是用于备份或类似的。如果是这样,我制作了一个bat文件,并且计划任务每​​周运行一次。

尝试制作一个bat文件。

打开记事本并输入

xcopy "file location" "file destination" /i /e /y /z
Run Code Online (Sandbox Code Playgroud)

例如

xcopy "c:\allmusic\mp3\" "e:\music\" /i /e /y /z
Run Code Online (Sandbox Code Playgroud)

将文件另存为 .bat(例如“copyFiles.bat”)

您可以有多行,但每行一行。例如

xcopy "c:\allmusic\mp3\" "e:\music\" /i /e /y /z
xcopy "c:\allmusic\wav\" "e:\music\" /i /e /y /z
xcopy "c:\allmusic\wmv\" "e:\music\" /i /e /y /z
Run Code Online (Sandbox Code Playgroud)

请注意, 和/i /y /e具有/z可能需要或不需要的含义(例如覆盖),请参阅此处的列表:

/A Copies only files with the archive attribute set, doesn't change the attribute.  
/M Copies only files with the archive attribute set, turns off the archive attribute.  
/D:m-d-y Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time.  
/EXCLUDE:file1[+file2][+file3]... Specifies a list of files containing strings. When any of the strings match any part of the absolute path of the file to be copied, that file will be excluded from being copied. For example, specifying a string like \obj\ or .obj will exclude all files underneath the directory obj or all files with the .obj extension respectively.  
/P Prompts you before creating each destination file.  
/S Copies directories and subdirectories except empty ones.  
/E Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T.  
/V Verifies each new file.  
/W Prompts you to press a key before copying.  
/C Continues copying even if errors occur.  
/I If destination does not exist and copying more than one file, assumes that destination must be a directory.  
/Q Does not display file names while copying.  
/F Displays full source and destination file names while copying.  
/L Displays files that would be copied.  
/H Copies hidden and system files also.  
/R Overwrites read-only files.  
/T Creates directory structure, but does not copy files. Does not include empty  directories or subdirectories. /T /E includes empty directories and subdirectories.  
/U Copies only files that already exist in destination.  
/K Copies attributes. Normal Xcopy will reset read-only attribute  
/N Copies using the generated short names.  
/O Copies file ownership and ACL information.  
/X Copies file audit settings (implies /O).  
/Y Suppresses prompting to confirm you want to overwrite an existing destination file.  
/-Y Causes prompting to confirm you want to overwrite an existing destination file.  
/Z Copies networked files in restartable mode.   
Run Code Online (Sandbox Code Playgroud)

您还可以使用“移动”,类似于剪切和粘贴

例如

移动“源”“目的地”

move "c:\allmusic\mp3\" "e:\music\" /i /e /y /z
move "c:\allmusic\wav\" "e:\music\" /i /e /y /z
move "c:\allmusic\wmv\" "e:\music\" /i /e /y /z
Run Code Online (Sandbox Code Playgroud)

编辑

要通过循环复制各个文件夹,请尝试

for /f %%f in ('dir /b c:\')  do (
cd\
cd %%f
copy *.mp3 "e:\music"

for /f %%g in ('dir /b %%f')  do (
cd\
cd %%g
copy *.mp3 "e:\music"


for /f %%h in ('dir /b %%g')  do (
cd\
cd %%h
copy *.mp3 "e:\music"
pause
)
)
)
Run Code Online (Sandbox Code Playgroud)

注意,这会产生 3 层子文件夹