蝙蝠与字符的文件夹放&preFIX文件名;后缀带有日期 [英] Bat to Prefix File names with folder characters & suffix with date

查看:297
本文介绍了蝙蝠与字符的文件夹放&preFIX文件名;后缀带有日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个完整的新手,当涉及到BAT / CMD的东西。
我可以做的非常非常基本与谷歌一点点帮助! &安培;当我的意思是在说XCOPY基本IM,使用Robocopy等。

I'm a complete newbie when it comes to bat/cmd stuff. I can do the very very basics with a little help from google! & when i mean basic im talking xcopy, robocopy etc.

我试图写一个code,将提取1从当前文件夹和放5个字符;子文件夹中的文件重命名也与当前日期的后缀。

I am trying to write a code that will extract the 1st 5 characters from the current folder & rename files within a subfolder but also suffix with the current date.

所以这基本上就是我尝试做的。

So this is basically what im trying to do.

W:\\ 12345_folder 这是我想提取从12345主文件夹

W:\12345_folder This is the main folder that I want to extract the 12345 from.

W:\\ 12345_folder \\文件夹中这是对于那些要重命名的文件的位置

W:\12345_folder\subfolder This is the location for the files that are to be renamed

目前的子文件夹中的文件的名称如下

Current name of files within subfolder are as follows

FILE1.TXT
FILE2.TXT
file3.txt

重命名他们应该是如以下后

After renaming they should be as below

12345文件1 2014-10-02.txt
12345文件2 2014-10-02.txt
12345 file3的2014-10-02.txt

我所有的努力都白费了。我可以用这个获取日期。但是,重命名文件名,整个功放&;不保留现有的文件名。

All my efforts have been in vain. I can get the date using this. But it renames the whole filename & does not retain the existing filename.

FOR / F令牌= 1-5 delims = /%%的(%DATE%)D不改名的* .txt%%摹%%的F - %%Ë - %% d.txt

和我也一直在玩这个:

为%%的(%CD%)z的做(
   对于一个%%中(%%〜DPZ%\\)做(
      重命名**。TXT%%〜NXA-.TXT))

但同样这将覆盖整个文件名,不保留现有的文件名。

But again this overwrites the whole filename and does not retain the existing file name.

我要再次强调,我是一个完整的新手,所以要温柔和放大器;你的帮助是很大的AP preciated。

I must stress once again I am a complete novice so be gentle & your help is greatly appreciated.

推荐答案

这个问题似乎是与Windows重命名命令有一些错误,特别是与分配prefixes和后缀(见文末链接)。

The problem appears to be with the RENAME command in Windows has some bugs, specifically with assigning prefixes and suffixes (see bottom link).

我只是做了部分答案,因为我没能得到最新的工作作为后缀。但是,这将让你preFIX文件名与您选择的preFIX,包括日期的目录。

I only did part of the answer because I wasn't able to get date working as a suffix. But, this will allow you to prefix filenames in a directory with the prefix of your choosing, including the date.

我试图让一个的日期作为后缀解决方案的工作,但我不得不与我的版本CMD以下没有成功:

I tried to get a "date as a suffix" solution working, but I had no success with the following on my version of cmd:

    REN *.txt ????????????????abc.txt.x
    REN *.x *

返回:无效的名称

Returns: Invalid name

下面是我的替代解决方案,以增加preFIX日期。为了您的首批例如,创建两个批处理文件:

Here is my alternate solution, to add a prefix date. For your first batch example, create two batch files:

仁prefix.bat

renprefix.bat

    %4
    FOR %%v IN (%1) DO CALL %0 %1 %2 %%v GOTO:Part2
    ATTRIB -h %2%1
    GOTO End
    :Part2
    REN %3 %2%3
    ATTRIB +h %2%3
    :End

然后,使用上面的批处理文件在你的例子:

Then, use the above batch file in your example:

rendate.bat

rendate.bat

    for /f "tokens=1-5 delims=/ " %%d in ("%date%") do renprefix.bat *.txt %%g%%f-%%e-%%d

来源:
http://www.lagmonster.org/docs/DOS7/z-ren1.html
4.添加preFIX

Source: http://www.lagmonster.org/docs/DOS7/z-ren1.html "4. Adding a prefix"

这篇关于蝙蝠与字符的文件夹放&preFIX文件名;后缀带有日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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