Tom's Guide | Tom's Hardware | Tom's Games | PC Safety Suite
![]() |
![]() |
![]() |
Comment:
Hi
I am rookie ot batch.
I have a requirememnt where, I have to read from a text file which looks like thisa,test.txt
s,Files.txt
a,ForCommand.txta is for application file and s is for system file
I need to find all the attributes,creation date,modified date of these files and
write these details into a new file with name of the file.So I achieve so far is , I am able to get some of the parameters of the files .
1)
My loop is running one time extra which returens blank value for last time.2) I need to get parameters like creation date, last accessed and owner of the file ?
I am pasting my code below
set varText=complist.txt
set varText=%varText%for /f "tokens=1-2 delims=," %%T in (%varText%) do (
if %%T equ a Call :app %%U
if %%T equ s Call :sys %%U
):app
echo " I am in App"
echo FileName = %~nx1
echo FileSize = %~z1
echo TimeStamp = %~t1
echo FullPathofFile = %~f1
echo ShortPathFile = %~s1
echo Attribute = %~a1goto end
:sys
echo " I am in sys"
echo FileName = %~nx1
echo FileSize = %~z1
echo TimeStamp = %~t1goto end
:end
:: Done
kaps
+1 | ![]() |
1. It's not your loop running one extra time. It's because at the end of your loop you fall through to the :app section because you've forgotten to put "goto end".
By the way, you don't need an explicit end label: if you say goto :eof it will go to the end, as there was an :eof label at the end of your file.
Also, what's the purpose of this line:
set varText=%varText% ? It doesn't do anything.2. You'll need to call an external utility for that (which you can then use with the for /f command). I'm not sure if there is one that comes with Windows. Try Googling.
+1 | ![]() |
Hi
Thanks klint for quick reply.I have put gottoend before :app and it stopped and it's coming out of loop as required.
In vartext I am storing my file name.
Now please advise
1) This is working fine
echo FileName = %~nx1But I want to store/set this into a variable filename as I need to use it later on with my external command.
echo FileName = %~nx1
echo FileSize = %~z1
echo TimeStamp = %~t1
echo FullPathofFile = %~f1
echo ShortPathFile = %~s1
echo Attribute = %~a1How I can store these results in a variabls.
2)
Also, I found one utility from microsoft for checking checksum of a file
For /F "Tokens=1" %%I in ('FCIV %1%') Do Set checksum=%%I
I am using like above and storing value in checksum.
Thanks for all the help, Since I am writing a big batch file, I may ask some questions on this forum, I need to throw all the result in a file at some partiular location each time it ran. I am doing googling to read and find more before posting here.
thanks
rgds
kapskaps
+1 | ![]() |
You can do this:
set FileName=%~nx1
set FileSize=%~z1etc. Don't put spaces around the = sign, or else the variable name will include the trailing space.
+1 | ![]() |
Hi
I want to echo text in a file.
I am doing like thisecho Start Component >Kapstestnew.txt
echo Name = "KapstestnewReport" >>Kapstestnew.txt
echo Description = "Kapstestnew for Ross Stores" >>Kapstestnew.txtI have a huge text to echo in a file.
Is it possible to echo the whole text line by line without writing echo in starting and/or file name >>Kapstestnew.txt at the end of each line.
Basically echo a chunk of data staright into file like
echo blah blah.....
blah blah
> file.txtplease let me know.
Rgds
kaps
kaps
+1 | ![]() |
I don't think so. Well, not unless you use another language or utility - I think you can only do it line-by-line in native batch. But if anyone knows a way, I would be interested to know how to do it too.
For example, in many Unix shells you can do this:
cat <<end >file.txt
your text goes here
in multiple lines
end
![]() |
change file name (extensi...
|
Move files over 850kb
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.