简体   繁体   English

批处理文件,用于根据文件名将文件移动到文件夹

[英]Batch file for moving files to folders based on filenames

I use Dropbox to automatically upload all the photos/videos I take from my phone to a folder "My Dropbox\\Camera Uploads". 我使用Dropbox自动将从手机拍摄的所有照片/视频上传到文件夹“ My Dropbox \\ Camera Uploads”。 So this is full of files like: 因此,其中充满了以下文件:

2015-06-09 10.11.19.jpg 2015-06-09 10.11.19.jpg

2015-09-11 09.28.46.mp4 2015-09-11 09.28.46.mp4

I'd now like a batch file to move these to the correct folder (creating it if necessary) "..\\Photos\\Family\\YYYY-MM" where YYYY-MM is the year and month of the photo (ie the first seven characters of the filename). 我现在想将批处理文件移动到正确的文件夹(如有必要,请创建它)“ .. \\ Photos \\ Family \\ YYYY-MM”,其中YYYY-MM是照片的年月(即前七个)文件名的字符)。

(It has to be a relative rather than absolute path as this Dropbox folder is shared across machines with XP, Vista and Windows 7 OSs, so the first part of the path is different on each.) (它必须是相对路径,而不是绝对路径,因为此Dropbox文件夹是在装有XP,Vista和Windows 7操作系统的计算机之间共享的,因此路径的第一部分各不相同。)

I've found similar batch files and tried to tweak them, but just can't get it to work. 我找到了类似的批处理文件,并试图对其进行调整,但无法使其正常工作。 Many thanks for your help. 非常感谢您的帮助。

You can use this script (put it in a file with extension .bat) and start it: 您可以使用此脚本(将其放入扩展名为.bat的文件中)并启动它:

@echo off
setlocal enabledelayedexpansion
rem For each file in your folder
for %%a in (*.*) do (
    echo filename=%%a
    rem check if the it is not our script
    if "%%a" NEQ "%0" (
        set foldername=%%a
        set foldername=..\Photos\Family\!foldername:~0,7!
        echo foldername=!foldername!
        rem check if forlder exists, if not it is created
        if not exist "!foldername!" mkdir "!foldername!"
        rem Move (or change to copy) the file to directory
        move "%%a" "!foldername!\"
    )
)

暂无
暂无

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

相关问题 批处理文件,用于基于文件名创建文件夹并移动文件 - Batch file for creating folders based on filenames, and moving files 根据名称和带有批处理文件的课程代码将文件移动到文件夹 - Moving files to folders based on Name and Course Code with Batch File Windows批处理文件:根据输入文件(目标文件名)重命名文件(可能在多个文件夹中) - Windows batch file: rename files (possibly in multiple folders) based on input file (of target filenames) 需要一个可以根据文件名查找文件夹的批处理文件 - Need a batch file that can find folders based on filenames 如何通过批处理文件基于可变长度文件名创建文件夹 - How to create folders based on variable length filenames through batch file 批处理文件以创建文件夹并根据文件名移动文件 - Batch file to make folders and move files according to filenames Windows批处理脚本,用于根据用于巨大数据量的文件名将文件移动到其他文件夹 - Windows Batch Script for moving files to different Folders based on File Name for Huge Data Volume 基于多个文件名批量创建多个文件夹,并将多个相关文件移动到创建的文件夹中 - Batch Create Several Folders Based on Multiple Filenames, and Move Multiple Related Files to The Created Folders 批处理脚本以基于文件名创建文件夹 - Batch script to create folders based on filenames 使用批处理文件移动多个文件夹 - Moving multiple folders with batch file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM