Page 1 of 1

Create a file to all drives

Posted: Thu Dec 04, 2008 7:13 am
by alemrantareq
Hi everybody,
I need a solution. I want to create a file "MyFile.txt" in all the drives. How to do that? I've tried this script -

Code: Select all

on mouseUp
put the volumes & "/MyFile.txt" into tfile
open file tfile
end mouseUp
it creates that file only into the last volume, not all the volumes. Pls, show me the way....

Posted: Thu Dec 04, 2008 11:10 am
by Mark
Dear alemrantareq,

The volumes returns a linefeed-delimited list. You need to make a repeat structure that, with each loop, takes a line from the list and puts it, together with "/My File.txt" into a variable. You can use this variable with the open command.

Best,

Mark

Posted: Thu Dec 04, 2008 1:26 pm
by Janschenkel
You would need a repeat similar to the one below

Code: Select all

on mouseUp
  repeat for each line theVolume in the volumes
    put "Test" into URL (file:" & theVolume & "/test.txt")
  end repeat
end mouseUp
HTH,

Jan Schenkel.

Posted: Fri Dec 05, 2008 12:57 pm
by alemrantareq
Hi Janschenkel,
Thanks for your reply. Thanks for your scripting. I can make "Test.txt" to the all volumes by appling this script -

Code: Select all

on mouseup
 repeat for each line theVolume in the volumes
 put empty into url ("file:" & theVolume & "/Test.txt")
end mouseUp
After making, if I go to check that file by this script -

Code: Select all

on mouseUp
 repeat for each line theVolume in the volumes
 put theVolume & "/Test.txt" into tfile
 if there is a file tfile then
  answer "Found"
 end if
end mouseUp
But it doesn't work.
Again, if I try to make that file by this script -

Code: Select all

on mouseup
 repeat for each line theVolume in the volumes
 put url ("file:" & theVolume & "/Test.txt") into myfile
 open file myfile
end mouseUp
It doesn't work too. Why? Pls, help.....

Posted: Fri Dec 05, 2008 1:22 pm
by Mark
Dear alemrantareq,

You need to close your repeat loops. Repeat loops look like this:

Code: Select all

repeat for each line myLine in myList
  -- do everything between repeat and end repeat
  -- many times
end repeat
Do your scripts work, if you close the repeat loops correctly?

Best regards,

Mark

Posted: Sat Dec 06, 2008 5:14 am
by alemrantareq
Hi Mark,
Thanks for your reply and sorry to say I forgot to write "end repeat" in this forum but it was in my script and having it, I couldn't check that file using the second code and couldn't make that file using the third code.

Posted: Sat Dec 13, 2008 12:26 pm
by alemrantareq
Hi everybody,
Its a ling time nobody takes a response for my problem. I repeated my problem again - I want to check a text file in all of my volumes. To do this, I've made a script for a btn -

Code: Select all

on mouseUp 
 repeat for each line theVolume in the volumes 
 put theVolume & "/Test.txt" into tfile 
 if there is a file tfile then 
  answer "Found" 
 end if 
 end repeat
end mouseUp
But having the text file in some of my volumes, it doesnt show the message. Why ????????????

Posted: Sat Dec 13, 2008 1:17 pm
by malte
Hi alemrantareq,

did you actually look at the value of the volumes?

In the messagebox:

put the volumes

What do you get there? Are all your drives listed in there? Are you logged in with permissions to write to / read from all drives?

Your script looks just fine to me. If it does not answer it is either, because the file is not there (you could check that with an else statement after your answer command) or because an error occured (check the result instead of it. If the result is not empty, something went wrong) and see what you got there.

Hope that helps a bit,,

Malte

Posted: Mon Dec 15, 2008 11:21 am
by alemrantareq
Hi malte,
Thanks for your reply. After getting your reply, I made another btn with a new stack and then put my script into it. It works nicely. I think my old stack had one or more problems.