You are on page 1of 3

Hi I am rookie ot batch. I have a requirememnt where, I have to read from a text file which looks lik e this a,test.

txt s,Files.txt a,ForCommand.txt a 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 file s . 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 t he 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 echo echo echo echo echo FileName = %~nx1 FileSize = %~z1 TimeStamp = %~t1 FullPathofFile = %~f1 ShortPathFile = %~s1 Attribute = %~a1

goto end :sys echo echo echo echo " I am in sys" FileName = %~nx1 FileSize = %~z1 TimeStamp = %~t1

goto end :end

:: Done kaps

1. It's not your loop running one extra time. It's because at the end of you r loop you fall through to the :app section because you've forgotten to put "got o end". By the way, you don't need an explicit end label: if you say goto :eof it wi ll 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.

Hi Thanks klint for quick reply. I have put gottoend before :app and it stopped and it's coming out of loop a s required. In vartext I am storing my file name. Now please advise 1) This is working fine echo FileName = %~nx1 But I want to store/set this into a variable filename as I need to use it la ter on with my external command. echo echo echo echo echo echo FileName = %~nx1 FileSize = %~z1 TimeStamp = %~t1 FullPathofFile = %~f1 ShortPathFile = %~s1 Attribute = %~a1

How 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 parti ular location each time it ran. I am doing googling to read and find more before posting here. thanks

rgds kaps kaps You can do this: set FileName=%~nx1 set FileSize=%~z1 etc. Don't put spaces around the = sign, or else the variable name will include the trailing space. Hi I want to echo text in a file. I am doing like this echo Start Component >Kapstestnew.txt echo Name = "KapstestnewReport" >>Kapstestnew.txt echo Description = "Kapstestnew for Ross Stores" >>Kapstestnew.txt I have a huge text to echo in a file. Is it possible to echo the whole text line by line without writing echo in start ing 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.txt please let me know. Rgds kaps 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 w ould 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

You might also like