爱问知识人 爱问教育 医院库

纠正答案:求提取txt文件第一行作为文件名的批处理命令bat

首页

纠正答案:求提取txt文件第一行作为文件名的批处理命令bat

纠正答案:求提取txt文件第一行作为文件名的批处理命令bat 

上次给的答案不太直接,Shortway 大师给的方法很不错。
Shortway 大师,您能否再加段代码,文件名太长了, 30个字节以内最好
积分不足,改天一定奉送60分

提交回答
好评回答
  • 2008-12-29 10:02:14
      'bat对文件的读写、判断等操作极弱,所以推荐VBS。
    '使用也很简单:记事本输入→保存到目标文件夹,命名为“RenameText。vbs”文件→双击运行。
    ----代码开始-----
    Option Explicit 
    On Error Resume Next ' 容错语句,避免程序崩溃 '有可能重命名文件已经存在,忽略错误。
       Dim fso,fs,f Dim i Dim strNewName Const strCurrentPath = "。" '当前目录 Msgbox "根据文本文件第一行批量重命名的VBS程序" & vbcrlf & vbcrlf & "Created By Shortway",0," " Set fso = Wscript。
      CreateObject("Scripting。FileSystemObject") Set fs = fso。GetFolder(strCurrentPath)。Files i = 0 For Each f In fs '遍历当前文件夹内每个文件 If LCase(right( ,3))="txt" Then '判断是否是文本文件 strNewName = Trim(fso。
      OpenTextFile(f, 1, False)。ReadLine) '得到第一行 '以下剔除不能作文件名的特殊字符 strNewName = Replace(strNewName, "\", "") strNewName = Replace(strNewName, "/", "") strNewName = Replace(strNewName, ":", "") strNewName = Replace(strNewName, "*", "") strNewName = Replace(strNewName, "?", "") strNewName = Replace(strNewName, """", "") strNewName = Replace(strNewName, ">", "") strNewName = Replace(strNewName, "<", "") strNewName = Replace(strNewName, "|", "") strNewName = left(strNewName,30) '有时第一行文字太多了,就选30个字符了 =strNewName & "。
      txt" i = i + 1 End if Next Msgbox i & "个文件改名完成!(忽略重名)" Set fs = Nothing Set fso = Nothing 。

    s***

    2008-12-29 10:02:14

类似问题

换一换
  • 程序设计 相关知识

  • 电脑网络技术
  • 电脑网络

相关推荐

正在加载...
最新问答 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):