批处理文件根据名称将文件夹放入其他文件夹 [英] Batch file put folders into other folders depending on name

查看:155
本文介绍了批处理文件根据名称将文件夹放入其他文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人问过类似的问题(自动将文件放入文件夹 ),但我正在努力转换上述问题中的答案以适合我的需要.

A very similar question to this has been asked (Put files automatically in folders) however I am struggling to convert the answer in the aforementioned question to suit my needs.

我的问题是我需要使用其名称的一部分将文件夹移动到其他文件夹,之前回答的问题是关于移动文件.

My problem is that I need to move folders into other folders using a section of their name, the question that was answered before was about moving files.

我的文件夹上有日期和时间戳记2016-08-23 15.23.45.我需要将这些文件夹移动到另一个仅在2016-08-23上标有日期的文件夹.

My folders have date and time stamps on them 2016-08-23 15.23.45. I need to move these folders to another folder that has just the date on them 2016-08-23.

作为另一个小的要求,由于我不太熟悉Windows批处理文件,因此有人可以告诉我将文件路径放入批处理文件的位置.

As another small request, since I'm not very skilled with windows batch files, could someone please tell me where I will need to put my file paths into the batch file.

推荐答案

我需要使用其名称的一部分将文件夹移动到其他文件夹中

我的文件夹上有日期和时间戳记2016-08-23 15.23.45.我需要将这些文件夹移动到另一个只有日期2016-08-23

My folders have date and time stamps on them 2016-08-23 15.23.45. I need to move these folders to another folder that has just the date on them 2016-08-23

使用以下批处理文件(test.cmd):

Use the following batch file (test.cmd):

@echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2" %%d in ('dir /a:d /b') do (
  if not exist %%d md %%d
  if [%%e] neq [] move "%%d %%e" %%d >nul 2>&1
  )
endlocal

示例用法:

F:\test>dir /a:d /b /s
F:\test\2016-08-23 15.23.45
F:\test\2016-08-23 15.23.46
F:\test\2016-08-23 15.23.47
F:\test\2016-08-23 15.23.48

F:\test>test

F:\test>dir /a:d /b /s
F:\test\2016-08-23
F:\test\2016-08-23\2016-08-23 15.23.45
F:\test\2016-08-23\2016-08-23 15.23.46
F:\test\2016-08-23\2016-08-23 15.23.47
F:\test\2016-08-23\2016-08-23 15.23.48

F:\test>


进一步阅读

  • Windows CMD命令行的AZ索引-与Windows cmd行相关的所有内容的绝佳参考.
  • 用于/f -根据另一个命令的结果循环命令.
  • dir -显示文件和子文件夹的列表.
  • 如果-有条件地执行命令.
  • md -创建目录-创建一个新文件夹.
  • 移动-将文件从一个文件夹移动到另一个文件夹.
  • 重定向-重定向运算符.

  • Further Reading

    • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
    • for /f - Loop command against the results of another command.
    • dir - Display a list of files and subfolders.
    • if - Conditionally perform a command.
    • md - Make Directory - Creates a new folder.
    • move - Move a file from one folder to another.
    • redirection - Redirection operators.
    • 这篇关于批处理文件根据名称将文件夹放入其他文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆