I need a batch file or text file generation, please.
Moderator: DosItHelp
I need a batch file or text file generation, please.
I'm using Windows 7, and I have a folder with 1683 folders inside it, each containing an issue of the Magnet (a pre-war children's (and adults, the appeal was universal) weekly story paper - http://friardale.co.uk/Magnet/Magnet.htm).
Each of the folders is merely a number;
0001
0002
0003
0004
0005
etc, and I want to edit these so that they also contain the name of each individual story, i.e.;
0001 The Making of Harry Wharton
0002 The Taming of Harry
0003 The Mystery of Greyfriars
0004 Chums of the Remove
0005 Kidnapped
etc. But rather than edit each folder name manually, I'd rather use a batch file, something like;
Rename 0001 "0001 The Making of Harry Wharton"
Rename 0002 "0002 The Taming of Harry"
Rename 0003 "0003 The Mystery of Greyfriars"
Rename 0004 "0004 Chums of the Remove"
Rename 0005 "0005 Kidnapped"
but for all 1683 files of course (and there would need to be quotation marks, of course, in case the name included spaces). And I was wondering if there was a way to generate a text file that would scan the folder, and so find that there was 1683 subfolders and for each subfolder add a line to the text file of;
rename [folder name] "[folder name] "
(the above ends up with a space before the second quotation maeks), so that I end up with;
Rename 0001 "0001 "
Rename 0002 "0002 "
Rename 0003 "0003 "
Rename 0004 "0004 "
Rename 0005 "0005 "
(up to 1683, of course), so that all I have to do then is to manually enter the name of each story, rename the .txt to .bat, and run it.
If this isn't possible, then can someone use Microsoft Word or whatever to auto-generate a text file that contains what I want, please, and post it here. But a program or batch file that could be used to automatically generate the list would be preferable, as then I could use it for other things in the future.
Thanks for any answers.
Each of the folders is merely a number;
0001
0002
0003
0004
0005
etc, and I want to edit these so that they also contain the name of each individual story, i.e.;
0001 The Making of Harry Wharton
0002 The Taming of Harry
0003 The Mystery of Greyfriars
0004 Chums of the Remove
0005 Kidnapped
etc. But rather than edit each folder name manually, I'd rather use a batch file, something like;
Rename 0001 "0001 The Making of Harry Wharton"
Rename 0002 "0002 The Taming of Harry"
Rename 0003 "0003 The Mystery of Greyfriars"
Rename 0004 "0004 Chums of the Remove"
Rename 0005 "0005 Kidnapped"
but for all 1683 files of course (and there would need to be quotation marks, of course, in case the name included spaces). And I was wondering if there was a way to generate a text file that would scan the folder, and so find that there was 1683 subfolders and for each subfolder add a line to the text file of;
rename [folder name] "[folder name] "
(the above ends up with a space before the second quotation maeks), so that I end up with;
Rename 0001 "0001 "
Rename 0002 "0002 "
Rename 0003 "0003 "
Rename 0004 "0004 "
Rename 0005 "0005 "
(up to 1683, of course), so that all I have to do then is to manually enter the name of each story, rename the .txt to .bat, and run it.
If this isn't possible, then can someone use Microsoft Word or whatever to auto-generate a text file that contains what I want, please, and post it here. But a program or batch file that could be used to automatically generate the list would be preferable, as then I could use it for other things in the future.
Thanks for any answers.
Re: I need a batch file or text file generation, please.
The .doc versions of the file downloads include the title - do you have these or the .pdf versions, or the .mobi versions?
Re: I need a batch file or text file generation, please.
foxidrive wrote:The .doc versions of the file downloads include the title - do you have these or the .pdf versions, or the .mobi versions?
I have the PDF versions, but I converted them all to .jpg files so I could use (the fantastic picture viewer) Irfanview, as I don't like .pdf files.
Unfortunately, only some of the Magnet issues are available in .doc format, but all are in .pdf format.
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: I need a batch file or text file generation, please.
Kerr Avon wrote:foxidrive wrote:The .doc versions of the file downloads include the title - do you have these or the .pdf versions, or the .mobi versions?
I have the PDF versions, but I converted them all to .jpg files so I could use (the fantastic picture viewer) Irfanview, as I don't like .pdf files.
Unfortunately, only some of the Magnet issues are available in .doc format, but all are in .pdf format.
Then where are we supposed to get the list of names from? I am not typing that all out by hand.
Re: I need a batch file or text file generation, please.
If i'm not wrong, then the OP only wanted to have something like this "createList.bat" (untested):
But i recommend the use of OCR software like https://github.com/tesseract-ocr/tesseract/blob/master/README.md.
penpen
Code: Select all
@echo off
> "the.txt" (
for /F "tokens=*" %%a in ('dir /a:d /b') do (
echo rename "%%~a" "%%~a "
)
)
But i recommend the use of OCR software like https://github.com/tesseract-ocr/tesseract/blob/master/README.md.
penpen
Re: I need a batch file or text file generation, please.
ShadowThief wrote:Then where are we supposed to get the list of names from? I am not typing that all out by hand.
No, I just need a batch file that contains;
Rename 0001 "0001 "
Rename 0002 "0002 "
Rename 0003 "0003 "
Rename 0004 "0004 "
Rename 0005 "0005 "
(up to 1683, of course), and then I'll enter the text myself.
penpen wrote:If i'm not wrong, then the OP only wanted to have something like this "createList.bat" (untested):Code: Select all
@echo off
> "the.txt" (
for /F "tokens=*" %%a in ('dir /a:d /b') do (
echo rename "%%~a" "%%~a "
)
)
But i recommend the use of OCR software like https://github.com/tesseract-ocr/tesseract/blob/master/README.md.
penpen
That batch file text does exactly what I want - thanks very much! I've just ran it, and it created a 4KB text file containing the rename commands how I wanted them, i.e. (copy and pasted from the produced text file);
rename "0001" "0001 "
rename "0002" "0002 "
rename "0003" "0003 "
rename "0004" "0004 "
rename "0005" "0005 "
(up to 1683), so now all I have to do is enter the story titles, rename the .txt to .bat, run the batch file, and the renaming will be done.
Thanks again to both of you.
Re: I need a batch file or text file generation, please.
Just to push my luck (sorry!), is this possible?
I have a saved .txt file listing the titles, one per line, of the storie titles, i.e.;
The Making of Harry Wharton
The Taming of Harry
The Mystery of Greyfriars
Chums of the Remove
Kidnapped
through to the final name. Is it possible to have a batch file or program that will merge the text file that penpen's batch file made, with this text file, i.e. so that the text file containing;
rename "0001" "0001 "
rename "0002" "0002 "
rename "0003" "0003 "
rename "0004" "0004 "
rename "0005" "0005 "
and the text file with the names;
The Making of Harry Wharton
The Taming of Harry
The Mystery of Greyfriars
Chums of the Remove
Kidnapped
will produce a third text file containing;
rename "0001" "0001 The Making of Harry Wharton"
rename "0002" "0002 The Taming of Harry"
rename "0003" "0003 The Mystery of Greyfriars"
rename "0004" "0004 Chums of the Remove"
rename "0005" "0005 Kidnapped"
(up until 1683, of course). If this isn't possible, then fair enough, I'm just looking to save myself a lot of typing (well, copy and pasting, really). Thanks for any answers.
I have a saved .txt file listing the titles, one per line, of the storie titles, i.e.;
The Making of Harry Wharton
The Taming of Harry
The Mystery of Greyfriars
Chums of the Remove
Kidnapped
through to the final name. Is it possible to have a batch file or program that will merge the text file that penpen's batch file made, with this text file, i.e. so that the text file containing;
rename "0001" "0001 "
rename "0002" "0002 "
rename "0003" "0003 "
rename "0004" "0004 "
rename "0005" "0005 "
and the text file with the names;
The Making of Harry Wharton
The Taming of Harry
The Mystery of Greyfriars
Chums of the Remove
Kidnapped
will produce a third text file containing;
rename "0001" "0001 The Making of Harry Wharton"
rename "0002" "0002 The Taming of Harry"
rename "0003" "0003 The Mystery of Greyfriars"
rename "0004" "0004 Chums of the Remove"
rename "0005" "0005 Kidnapped"
(up until 1683, of course). If this isn't possible, then fair enough, I'm just looking to save myself a lot of typing (well, copy and pasting, really). Thanks for any answers.
Re: I need a batch file or text file generation, please.
A friend reminded me that this was easily done with Excel, and I've done it, and now all of the folders have the desired file names. Thanks to everyone for reading this, and for penpen for writing the batch file that creates the initial batch file.
Re: I need a batch file or text file generation, please.
Kerr Avon wrote:No, I just need a batch file that contains;
Rename 0001 "0001 "
Rename 0002 "0002 "
Rename 0003 "0003 "
Rename 0004 "0004 "
Rename 0005 "0005 "
(up to 1683, of course), and then I'll enter the text myself.
I was very amused when it became clear that you just wanted the text above.
Protip here Kerr - don't include a link and talk about a magazine and website and the pdf files, when none of those things are what you wanted. It's great to have good info, but here it threw me and others entirely off the scent.
![Smile :)](./images/smilies/icon_smile.gif)
No harm done, this time.
![Wink ;)](./images/smilies/icon_wink.gif)
Re: I need a batch file or text file generation, please.
@Kerr Avon:
If the name of the directories are numbers only, and if the episode names are in the line with the same number of the file "Titles.txt", you could do something like this:
(Don't use forbidden characters for file names.)
penpen
If the name of the directories are numbers only, and if the episode names are in the line with the same number of the file "Titles.txt", you could do something like this:
Code: Select all
@echo off
>"result.txt" (
for /F "tokens=1* delims=:" %%a in ('findstr /n "^" "Titles.txt"') do (
set /A "line=10000+%%~a"
call echo rename "%%line:~1%%" "%%line:~1%% %%~b"
)
)
penpen
Re: I need a batch file or text file generation, please.
foxidrive wrote:I was very amused when it became clear that you just wanted the text above.
Protip here Kerr - don't include a link and talk about a magazine and website and the pdf files, when none of those things are what you wanted. It's great to have good info, but here it threw me and others entirely off the scent.
No harm done, this time.
Understood, sorry mate.
penpen wrote:@Kerr Avon:
If the name of the directories are numbers only, and if the episode names are in the line with the same number of the file "Titles.txt", you could do something like this:(Don't use forbidden characters for file names.)Code: Select all
@echo off
>"result.txt" (
for /F "tokens=1* delims=:" %%a in ('findstr /n "^" "Titles.txt"') do (
set /A "line=10000+%%~a"
call echo rename "%%line:~1%%" "%%line:~1%% %%~b"
)
)
penpen
Thanks for that, I'll try it the next time I need something similar.
BTW, regarding bad filenames, I'd stupidly put some bad characters into the issue name text file, such as
The Smedly/Vernon Smith series
where of course the forward slash can't be used in a folder name. I should have realised straight away, as opposed to having to look through the text file AFTER some renames had failed, but human error will always be with us (if I'm involved, anyway!).