Answer the question
In order to leave comments, you need to log in
Is there a bat file code to rename all txt files in a folder, replacing the name with the first line of the file's content?
The folder contains many text files named File001.txt, File002.txt, etc. With the following content
File001.txt
Contents of the file: Winter evening at the dacha
Nina Dedlova Half-darkness. Not too late. Monday. Silence. Pine trees speak with winter. The air is clean and frosty ... And in the country I am alone.
File002.txt Contents of the file:
Coming of winter
Lyudmila Shishenina Fluffy snow - a swan coverlet, Magpie trampled in the morning. Patterns, circling, painted, And proudly walks on the carpet. etc.
We need a bat file to rename all files in the folder, replacing the name with the first line of the file's contents, for example:
File001.txt
File002.txt
, etc. Renames to:
Winter evening in the country. txt
The arrival of winter. txt
, etc.
Windows
Or a program that can.
Answer the question
In order to leave comments, you need to log in
Solution:
Updated PowerShell
Write batch:
@echo off
powershell -executionpolicy bypass -command "Get-ChildItem -Filter '*.txt' | foreach {Rename-Item $_.FullName """$(Get-Content $_.FullName ^ | Select-Object -First 1)$($_.Extension)"""}"
pause
exit
Solution cyberforum en
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question