|
Post by honky on Jul 13, 2023 15:19:40 GMT
Hello, with your code, who work fine, I should want to put the datas in a array, I have used many and many means and do not work Can you me heilp please Thank.
Your code: [/div][div]global upath$ call getUserProfile print upath$ upath$ = trim$(upath$) run "notepad ";upath$;"\Desktop\MyTextFile.txt" 'change MyTextFile.txt to the name of YOUR file. end
'get users homepath sub getUserProfile run "cmd.exe /c echo %userprofile% >UserHomePath.txt", HIDE do scan loop until fileExists(DefaultDir$, "UserHomePath.txt") open "UserHomePath.txt" for input as #1 upath$ = input$(#1, lof(#1)) close #1 if upath$ = "" then notice "Sorry, can't find user desktop path " : end kill DefaultDir$;"\UserHomePath.txt" end sub
'function for checking file existence function fileExists(path$, filename$) dim info$(0, 0) files path$, filename$, info$() fileExists = val(info$(0, 0)) 'non zero is true end function [/div][div]
|
|
|
Post by tsh73 on Jul 13, 2023 16:14:25 GMT
Honky, If you clearly explain what you want it would be beneficial for everybody. (you might even get solution by yourself, just by trying to explain. Yes it often works.)
Also generally "I tried this and that and it did not worked" is far superior then "I tried everyhing and nothing worked"
(things you did post allow others to see how you attempted to do it, and may be spot easy error; things that you DIDN'T post forces everyone to second-guess your version of "everyhing" you tried. Being that lazy, I'd rather not second-guess. )
|
|
|
Post by honky on Jul 13, 2023 16:46:17 GMT
@ tsh73: I tried a lot, when it doesn't work, I delete, what good is it to keep what doesn't work? The explanation: I have a blender addon that creates a file ".txt" on the desktop and fill it. Python cannot display the data ("notepad" is tiers software not accessible from the API). Since I couldn't reach the file (on the desktop), I created a thread for. "xxgeek" responded with a code that gives access to the file and display it (notepad). And now I can't put the data in an array. Please Help, my brain said "Out of service".
|
|
|
Post by xxgeek on Jul 13, 2023 17:43:31 GMT
Exactly what data are you talking about honky?
Do you mean you want a line by line list of the what's in the file?
If so, this should work. Use what you need and discard or edit the rest. Remember - Save code to a file in it's own folder before running.
dim anArray$(10000) ' 10,000 lines - may need increased/decreased, depends on the size of your file open upath$;"\Desktop\MyTextFile.txt" for input as #1 while eof(#1) = 0 x=x+1 line input #1, anArray$(x) print anArray$(x) wend close #1 end
Notice I used upath$ like in my original post. Means you need the top code, with this code, for this code to work.
eg:
dim anArray$(10000) ' 10,000 lines - may need increased/decreased, depends on the size of your file global upath$ call getUserProfile print upath$ print upath$ = trim$(upath$) 'run "notepad ";upath$;"\Desktop\MyTextFile.txt" 'change MyTextFile.txt to the name of YOUR file. open upath$;"\Desktop\MyTextFile.txt" for input as #1 while eof(#1) = 0 x=x+1 line input #1, anArray$(x) print "anArray$(";x;") = ";anArray$(x) wend close #1 end
'get users homepath sub getUserProfile run "cmd.exe /c echo %userprofile% >UserHomePath.txt", HIDE do scan loop until fileExists(DefaultDir$, "UserHomePath.txt") open "UserHomePath.txt" for input as #1 upath$ = input$(#1, lof(#1)) close #1 if upath$ = "" then notice "Sorry, can't find user desktop path " : end kill DefaultDir$;"\UserHomePath.txt" end sub
'function for checking file existence function fileExists(path$, filename$) dim info$(0, 0) files path$, filename$, info$() fileExists = val(info$(0, 0)) 'non zero is true end function
|
|
|
Post by honky on Jul 13, 2023 19:06:43 GMT
Thank you very much for your explanations; Yess I want put line by line, for traitment by JB
|
|
|
Post by xxgeek on Jul 13, 2023 19:29:33 GMT
You are welcome honky.
I'll assume you've got what you needed.
|
|
|
Post by honky on Jul 15, 2023 11:21:10 GMT
Yes, with your explanations I got there. Thank you.
|
|