Please help me create a txt
Moderator: DosItHelp
Please help me create a txt
Hi. I will start by admitting I love what batch files do but have no idea how they do it. I am trying to modify an existing .bat to do what I wish, but it is more difficult than I anticipated. I am attempting to create a .bat that will write a .txt to the active directory that lists the contents. I would like it to put a label at the top which is selected from an existing .txt then list the contents of the directory and delete anything from the list that is a .txt or .bat and then put the amount of free space at the bottom.
I would like a .txt that looks like this
"Title" I have a Title.txt that I'd like to be able to select from, it reads as listed below.
"directory contents"
"directory contents"
"directory contents"
Sometimes there are other .txt or .bat files here that I do not wish to be listed
"space free" Free
Title.txt contents
[1] "Title1"
[2] "Title 2"
[3] "Title 3"
as so on
I'd like the dos window to prompt me to select the appropriate title by selecting the associated number or give me the option to add a new title if desired.
I really appreciate any help anyone can give.
Sincerely,
Mike "The Batch Idiot" G
I would like a .txt that looks like this
"Title" I have a Title.txt that I'd like to be able to select from, it reads as listed below.
"directory contents"
"directory contents"
"directory contents"
Sometimes there are other .txt or .bat files here that I do not wish to be listed
"space free" Free
Title.txt contents
[1] "Title1"
[2] "Title 2"
[3] "Title 3"
as so on
I'd like the dos window to prompt me to select the appropriate title by selecting the associated number or give me the option to add a new title if desired.
I really appreciate any help anyone can give.
Sincerely,
Mike "The Batch Idiot" G
Re: Please help me create a txt
So what you need is a list of all files exist in the directory where the batch is and this list contain all files except the txt & bat files.
But do you want this list to be exported to a txt file after display on screen?
and do you want to list folder too?
But do you want this list to be exported to a txt file after display on screen?
and do you want to list folder too?
Re: Please help me create a txt
NOTE
I changed the Code, it now can take as many as titles you want, without the need to change any codes.
BUT The titles must be in that form "[number] title", the number is the title order and must be between [ ]
Title.txt:
The batch:
This code will list folders as well, to prevent that see line (31).
The Title.txt must be in the same folder as the batch, to put it in differant folder, must write the full location in the for commands in line (13 and 21)
I changed the Code, it now can take as many as titles you want, without the need to change any codes.
BUT The titles must be in that form "[number] title", the number is the title order and must be between [ ]
Title.txt:
Code: Select all
[1] First Title
[2] First Title
[3] First Title
[4] First Title
[5] First Title
[6] First Title
[7] First Title
[8] First Title
The batch:
Code: Select all
@echo off & cls & Title goymerac
:main
cls
setlocal enabledelayedexpansion
:: Display Title Names from Title.txt
echo.
echo Select Title:
echo -------------
For /F "tokens=*" %%A in ('type "Title.txt"') Do echo %%A
:: Set Each Title to a variable (unlimited titles).
echo.
set "num="
set /p "num=Which Title: "
if not defined num goto main
:: set the default printer
for /f "skip=2 tokens=*" %%a in ('find /I "!num!" "Title.txt"') do set Final_Title=%%a
:: Display Result
:display
cls
echo.
echo !Final_Title:~4!
echo.
:: Get a List of ALL files EXCEPT txt and bat files.
:: to prevent display of folders chanag below (line 49) for command to: For /F "tokens=*" %%A in ('Dir /B /A:-D "*.*"') Do (
For /F "tokens=*" %%A in ('Dir /B /A:D "*.*"') Do (
set files=%%A
IF not "!files:~-3!" == "txt" (
IF not "!files:~-3!" == "bat" (
echo ^> !files!
)
)
)
:: Get total Free space and set it to variable %free%
For /F "tokens=3,4,5 delims= " %%A in ('dir "*.*"') Do set free=%%A %%B
echo.
echo Total Free Space: !free!
:: Time to wait before making a log and then exit is about [5]sec
ping localhost -n 5 >nul
:: Make Log file of the output
>>Directory_log.log call :display
Exit /B
This code will list folders as well, to prevent that see line (31).
The Title.txt must be in the same folder as the batch, to put it in differant folder, must write the full location in the for commands in line (13 and 21)
Last edited by abc0502 on 13 Sep 2012 09:12, edited 2 times in total.
Re: Please help me create a txt
I edited the code above
Re: Please help me create a txt
Thank you for your reply. I am trying to list all the information in a txt that is created with the batch onto the current directory. I am trying to list only the folders in the current directory.
Re: Please help me create a txt
ok , i changed the code up
Re: Please help me create a txt
I'm almost there. It won't let me select a title from my Title.txt file that's on my c drive in the same place as my .bat file. It is putting
~4 at the top, and is there a way to show the free space in GB?
~4 at the top, and is there a way to show the free space in GB?
Re: Please help me create a txt
how is the titles in the title.txt file are written?
Re: Please help me create a txt
[1] Title 1
[2] Title 2
[2] Title 2
Re: Please help me create a txt
it should be working i tested again and it give me the correct title, but about the free size it a bit difficult to convert it to GB, cause i get the total from the cmd window when you write in it DIR command
write this and tell me the result instead of "!Final_Title:~4!" write "!Final_Title!" without the quotes
write this and tell me the result instead of "!Final_Title:~4!" write "!Final_Title!" without the quotes
Re: Please help me create a txt
It places an empty line at the top and on the second line
ECHO is off.
the free space issue could be solved if there is a way to do simple math on !free! by dividing it by 1073741824?
ECHO is off.
the free space issue could be solved if there is a way to do simple math on !free! by dividing it by 1073741824?
Re: Please help me create a txt
It works if I put the title.txt in the cd but it is on my c: and that is where i am running my .bat from too.
Re: Please help me create a txt
goymerac wrote:It works if I put the title.txt in the cd but it is on my c: and that is where i am running my .bat from too.
what do you mean with put title.txt in the cd
Re: Please help me create a txt
current directory
sorry still bad with commands
sorry still bad with commands