Hey guys, totally new to batch scripting. I have tons of file that need to be renames based on the user name, which is located in the file. for example the file content is such:
Directory of Y:\Bob\My Documents
14/01/2011 01:59 PM 10,411,520 MVI_1903_1.avi
1 File(s) 10,411,520 bytes
The file is named file1 but i need to rename it bob.txt
this seems simple and would make things a lot easier. thanks in advance
renaming files based on content
Moderator: DosItHelp
Re: renaming files based on content
Too less informations. You've tons of files -- OK, but where? All in the same directory? All with the same file extension?
Generally (for a single file, e.g. "file1.txt"):
This should return "Bob" in your case.
Regards
aGerman
Generally (for a single file, e.g. "file1.txt"):
Code: Select all
for /f "tokens=2*" %%a in ('findstr /c:"Directory of " "file1.txt"') do (
for /f "tokens=2 delims=\" %%c in ("%%b") do echo %%c
)
This should return "Bob" in your case.
Regards
aGerman
-
- Posts: 10
- Joined: 08 Mar 2011 08:54
Re: renaming files based on content
Directory is in the root of the Y: drive, all files are in the same directory, all with the extension of .txt
This did the trick, thanks again
for /f "tokens=2*" %%a in ('findstr /c:"Directory of " "*.txt"') do (
for /f "tokens=2 delims=\" %%c in ("%%b") do Ren *.txt %%c.txt
)
This did the trick, thanks again
for /f "tokens=2*" %%a in ('findstr /c:"Directory of " "*.txt"') do (
for /f "tokens=2 delims=\" %%c in ("%%b") do Ren *.txt %%c.txt
)