General discussion

Locked

batch script to rename .txt file using the first line of the file

By nigel.baldry ·
Tags: Off Topic
Hi

I have a number of text files which are named nnn.txt, I want to rename them using the first line of the text file. ie 123.txt becomes my new name.txt. Can anyone help.

This conversation is currently closed to new comments.

13 total posts (Page 2 of 2)   Prev   01 | 02
| Thread display: Collapse - | Expand +

All Comments

Collapse -

I thought type returned the description

by Slayer_ In reply to The PowerShell is one lin ...

But if it is the extension, then your right, it would have been better :)

But anyways, I was initially trying to give him a solution that he could use and modify himself.

Collapse -

Renaming file

by nigel.baldry In reply to I thought type returned t ...

Hi

Thanks for your help. The VB script works a treat. I'll have a play with the .bat script when I have more time. I do use .bat files for some other tasks, and I've started to use VBS in Access, I do find VBS easier to follow, although it does tend to be a bit more long winded.

Collapse -

Well you can condense VBS almost as bad as you can in DOS scripts

by Slayer_ In reply to Renaming file

people just mostly don't because we try and follow programing and readability standards.

This code should do the exact same thing, but it is impossibly unreadable. But it's only 2 lines of code.

Set FSO = CreateObject("Scripting.FileSystemObject")
For Each file In FSO.GetFolder("C:\Users\trevord\Desktop\Temp Export\").Files:file.move(file.ParentFolder & "\" & Left(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(file.OpenAsTextStream.ReadLine, "\", ""), "/", ""), ".", ""), ">", ""), "<", ""), "?", ""), ":", ""), "*", ""), "|", ""), Chr(34), ""), instr(1,Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(file.OpenAsTextStream.ReadLine, "\", ""), "/", ""), ".", ""), ">", ""), "<", ""), "?", ""), ":", ""), "*", ""), "|", ""), Chr(34), ""),"-") -1) & right(file.Name, len(file.Name) - InStrRev(file.Name, ".")+1)):Next

Back to After Hours Forum
13 total posts (Page 2 of 2)   Prev   01 | 02

Related Discussions

Related Forums