Batch Programming Help - Renaming Files

Score
0
Vote Up
February 15, 2012 at 18:49:13 Pacific
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..?


Reply ↓  Report •


#1
Vote Down
Score
0
Vote Up
February 20, 2012 at 06:27:47 Pacific

This sounds like a horrible idea.
Untested:
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


Reply ↓  Report •
Reply to Message Icon Start New Discussion
Related Posts

« extract data from text fi... I truly desire to become ... »