批处理文件排序文件夹 [英] Batch file to Sort folders
问题描述
我想建立简单的批处理文件的窗口,它移动文件夹的基础上她的名字位置。
例如,如果一个文件夹包含new.work.directory-ABC的基础上,单词工作我希望它被转移到H:\\工作。
如果该文件夹的名称包含基于词old.school.stuff-1S2学校就应该被移到H:\\学校
I'm trying to build simple Batch windows file that does move folder to location based on her name. For example, if a folder contain new.work.directory-abc, based on the word "work" i want it to be moved to h:\work. If the folder name contain old.school.stuff-1s2 based on the word "school" it should be moved to h:\school.
扫描目录将有新的文件夹中所有的时间,所以我会cron中的批次运行每隔1小时。
The scanned directory will have new folders all time, so i'll cron the batch to run every 1 hour.
谢谢!
推荐答案
如果你能在什么位置,关键字会出现在名称不是predict ....
If you cannot predict at what position the keyword will appear in the name....
@echo off
setlocal
:: path to hourly folders:
pushd "c:\temp\hourly"
for /d %%I in (h:\*) do (
for /d %%x in (*) do (
for /f %%A in ('echo %%~nx ^| find /i "%%~nI"') do (
set /p a="Moving %%x to %%I... "<NUL
move "%%x" "%%I" >NUL
echo Done.
)
)
)
popd
Assumtions:
- 您已经有
文件夹H:\\
成移动文件夹每小时
- You already have folders on
H:\
into which to move the hourly folders
工作原理
- 在第一个目录的名称上
H:\\
- 对于每个每小时目录,看能否先
H的名称:\\
目录被包含在每小时目录的名称在 - 如果是这样,那移动每小时目录下的第一个目录的
H:\\
- 循环对
h将第二个目录:\\
和重复
- Take the name of the first directory on
H:\
- For each hourly directory, see whether the name of first
H:\
directory is contained within the name of the hourly directory - If it is, move that hourly directory to the first directory on
H:\
- Loop to the second directory on
H:\
and repeat.
示例输出
C:\Temp\Hourly>dir *.
Volume in drive C has no label.
Volume Serial Number is CE09-0D42
Directory of C:\Temp\Hourly
02/06/2013 08:57 AM <DIR> .
02/06/2013 08:57 AM <DIR> ..
10/20/2011 01:17 PM <DIR> 99 Windows 7 Shortcuts
01/24/2013 02:00 PM <DIR> A sysinternals folder
06/18/2012 02:45 PM <DIR> funny
01/14/2013 12:47 PM <DIR> PortableApps
01/16/2013 09:44 AM <DIR> songs
02/06/2013 08:33 AM <DIR> This is a temp directory
01/24/2013 02:01 PM <DIR> user prompts
06/20/2012 08:00 AM <DIR> We Are Anonymous
0 File(s) 0 bytes
10 Dir(s) 176,419,254,272 bytes free
C:\Temp\Hourly>dir h:\*.
Volume in drive C has no label.
Volume Serial Number is CE09-0D42
Directory of h:\
08/02/2011 02:24 PM <DIR> 52bb3510d8007c2f356572
08/16/2011 06:35 AM <DIR> ATI
11/07/2012 01:22 AM <DIR> Desktop Document
09/20/2011 01:50 PM <DIR> Documentum
02/23/2011 08:07 AM <DIR> Drivers
01/04/2013 01:17 PM <DIR> ffe
12/19/2012 11:19 AM <DIR> flex_renamer
01/11/2012 02:44 PM <DIR> Games
01/08/2013 12:14 PM <DIR> gnuwin32
03/03/2011 09:32 AM <DIR> Intel
07/13/2009 10:20 PM <DIR> PerfLogs
09/17/2010 01:08 PM <DIR> PortableFrozenBubble
08/28/2012 02:27 PM <DIR> portaputty
11/13/2012 10:40 AM <DIR> Program Files
01/22/2013 02:30 PM <DIR> Program Files (x86)
06/01/2012 01:08 PM <DIR> SpamBayes
02/24/2011 04:21 PM <DIR> Symantec
01/24/2013 01:56 PM <DIR> Sysinternals
04/19/2011 08:35 AM <DIR> Tcl
04/19/2011 08:30 AM <DIR> TclDevKit
02/06/2013 08:52 AM <DIR> temp
02/19/2010 05:42 PM <DIR> universal print driver
11/07/2012 01:11 AM <DIR> Users
02/06/2013 08:56 AM <DIR> Windows
0 File(s) 0 bytes
24 Dir(s) 176,419,254,272 bytes free
C:\Temp\Hourly>movedir.bat
Moving A sysinternals folder to h:\Sysinternals... Done.
Moving This is a temp directory to h:\temp... Done.
Moving 99 Windows 7 Shortcuts to h:\Windows... Done.
C:\Temp\Hourly>dir *.
Volume in drive C has no label.
Volume Serial Number is CE09-0D42
Directory of c:\Temp\Hourly
02/06/2013 09:00 AM <DIR> .
02/06/2013 09:00 AM <DIR> ..
06/18/2012 02:45 PM <DIR> funny
01/14/2013 12:47 PM <DIR> PortableApps
01/16/2013 09:44 AM <DIR> songs
01/24/2013 02:01 PM <DIR> user prompts
06/20/2012 08:00 AM <DIR> We Are Anonymous
0 File(s) 0 bytes
8 Dir(s) 176,419,254,272 bytes free
C:\Temp\Hourly>
这篇关于批处理文件排序文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!