[英]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.