Windows批处理 - 将文件移动到基​​于文件名和文件夹放;延期 [英] Windows batch - Move files to folders based on file name & extension

查看:117
本文介绍了Windows批处理 - 将文件移动到基​​于文件名和文件夹放;延期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的批处理文件,虽然已经彻底搜查,结果发现了类似主题的话题,虽然没有覆盖我的precisely需要。

I am new to batch files although have searched thoroughly and found topics with a similar theme, although not covering what I precisely need.

返回故事:
我有保存时生成两个文件,​​一个.PDF和.XLSM的Excel文件。这些文件被保存到到进程文件夹中。

Back story: I have an excel file which when saved generates two files, a .PDF and an .xlsm. These files are saved into a 'To-Process' folder.

它们被命名为与以下命名约定:公司名称 - 日期,因此,例如'戴夫斯水暖 - 01-08-13.xlsm
戴夫斯水暖 - 01-08-13.pdf

They are named with the following naming convention: Company name - Date, so for example 'Daves Plumbing - 01-08-13.xlsm' 'Daves Plumbing - 01-08-13.pdf'

处理:
每周一次我手动移动到这些单独命名的文件夹按公司名称例如C:/文件/销售/ EXCEL / DAVES管道/
C:/ dociuments /销售/ PDF / DAVES水暖/

Processing: Once a week I manually move these into separately named folders by company name e.g C:/documents/sales/excel/daves plumbing/ C:/dociuments/sales/pdf/daves plumbing/

我AP $在公司名称p $ pciate空间没有帮助,但希望我们可以使用 - 作为分隔符

I appreciate spaces in the company name don't help, but hopefully we could use the - as a delimiter?

最后,我希望创建一个批处理文件,该文件将通过文件夹中的文件步进,读书的公司名称,并根据名和扩展名的每个文件移动到相应的文件夹自动上面的处理。

Ultimately I am looking to create a batch file which will automate the processing above by stepping through the files in the folder, reading the company name and moving each file to the relevant folder based on the name and extension.

我可以当我决定来处理任何一个时间有向上的文件夹中的50个文件。

I can have upwards of 50 files in the folder at any one time when I decide to process.

帮助的,这是很大的AP preciated,我希望我已经提供了足够的信息,看是否是可行的。

Help on this is greatly appreciated, I hope I have provided sufficient information to see if this is feasible.

非常感谢,
灰分

Many thanks, Ash

P.S
作为一个方面说明,我假设我不能合并之前,移动它们发送PDF文件作为电子邮件附件?例如执行批处理文件,通过电子邮件发送PDF文件至pre定义的电子邮件地址,然后两个PDF和XLSM移动到相关文件夹。这并不重要,只是好奇的批量处理的能力。

p.s As a side note, I am assuming I could not incorporate sending the PDF files as an email attachment prior to moving them? e.g execute batch file, send PDF's via email to pre-defined email address, then move both 'pdf' and 'xlsm' to relevant folders. This is not important, merely curious of the capabilities of batch processing.

推荐答案

编辑以使用不同的目标文件夹。不要使用 - 在批处理文件名,如果你打算在同一个文件夹中使用它

EDITED to use different destination folders. Don't use a - in the batch filename if you plan to use it in the same folder.

试试这个。它使用的第一个 - 在文件名作为分隔符,删除最后一个字符是一个空间,使一个目录,如果需要与否,以及将文件移动到相应的文件夹

Try this. It uses the first - in the filename as the delimiter, removes the last character which is a space, makes a directory if it needs it or not, and moves the files into the appropriate folder.

包含文件名!和%可能是一个问题。

Filenames containing ! and % could be an issue.

@echo off
cd /d "c:\To-Process"
setlocal enabledelayedexpansion
for %%a in (*-*.*) do (
   for /f "delims=-" %%b in ("%%a") do (
     set "f=%%b"
       if /i "%%~xa"==".pdf" (
         md "C:/documents/sales/pdf/!f:~0,-1!" 2>nul
         move "%%a" "C:/documents/sales/pdf/!f:~0,-1!" >nul
       )
       if /i "%%~xa"==".xlsm" (
         md "C:/documents/sales/excel/!f:~0,-1!" 2>nul
         move "%%a" "C:/documents/sales/excel/!f:~0,-1!" >nul
       )
   )
)

有批/ VBS脚本来发送邮件,带有附件。结果
谷歌对他们来说,也可以使用 BLAT 的Sendmail

There are batch/VBS scripts to send an email, with an attachment.
Google for them, or use Blat or Sendmail.

这篇关于Windows批处理 - 将文件移动到基​​于文件名和文件夹放;延期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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