Batch Programming Help - Renaming Files

February 15, 2012 at 18:49:13
Specs: Windows 7
So, I'm new to writing Batch files. I've got the basic algorithm, however it is the formatting and language I'm having problems with.

I'm trying to write a file that replace that will, for each and every text file found in "C:\files\" folder, switch it's file name with it's content.

E.g. "file1.txt", "file2.txt", "file3.txt", and "file4.txt" exist in "C:\files\" folder. In "file1.txt" there is a line of text containing the single word "alpha". The other text files have different words as content.
"file1.txt" containing the word "alpha" becomes "alpha.txt" containing the word "file1".

Here's my go at it:

FOR /R %%F IN (*.txt) DO (
set /p var= <Text.txt
RENAME %%F %var%
%%F > (*.txt)


It's not working and for the love of all that is holy, I can't get my head around it.

NOW...if I can get it to switch file names back AND forth using the same batch file......

I would be so gracious as to even give you an internet hug...., their not cheap y'know..?

See More: Batch Programming Help - Renaming Files

Report •

February 20, 2012 at 06:27:47
This sounds like a horrible idea.
setlocal enableDelayedExpansion
for %%a in (C:\files\*.txt) do {
  set /p var= < "%%a"
  del "%%a"
  > !var! echo %%~Na

How To Ask Questions The Smart Way

Report •
Related Solutions

Ask Question