Can load text file in Windows - not on the Mac?

I have some code that loads a text file into an array that works fine in windows, but fails on the Mac  I'm sure it's a path issue but I've spent several hours trying to work this out.
Windows code works fine:
    var textPath =  "c:\\temp\\textfile.txt";
     try {
        var myFile = File(textPath);
        var mymenuItems=[];
        var menuItems=[];
        myFile.open('r');
        while(!myFile.eof){
            mymenuItems.push(myFile.readln());
        myFile.close();
Mac Code Fails
  var textPath = '/User/wizbowes/Desktop/text.txt';
     try {
        var myFile = new File(textPath);  //tried both with and without new - same effect
        var mymenuItems=[];
        var menuItems=[];
       myFile.open('r');
   while(!myFile.eof){
            mymenuItems.push(myFile.readln());
When debugging on the mac myFile.eof shows true straight after I open the file and therefore never enters the loop to populate the array
What on earth am I doing wrong?

1. For files on your desktop you can use a shortcut.
var textPath = '~/Desktop/text.txt';
2. Make sure the file object is valid before you open for reading. The new keyword is not really needed it just make clear in the code that you are creating a new file object. However just creating a file object does not means that the file already exists. You could have an invalid path.
try {
        var myFile = new File(textPath);
        if(myFile.exists){
           // rest of the code
3. If you don't want to check that the file exists you could check the return of the file.open() method. It should return true if it opened the file when opening an existing file.
var openSuccess = myFile.open('r');
if(openSuccess){
    // some code that reads from the file here

Similar Messages

  • How can I remove files that do not contain the number 1 or ~1?

    I had to convert many .avi files.  The new names all contain ~1.  Those files I want to keep and remove the originals.  There are scripts to remove files with a numeral such as 1.  I need one to remove all files without the 1 or ~1. 
    I tried using a script that removed older files, but the new files seemed to have the same created dates and modified dates so that will just delete all the files.

    Thanks for your input.  I want to keep the files with a 1 or ~1 as it happens and delete the rest.  I have written some scripts.  I think I could write a script to delete all files with a 1, but of course that is not what I want.  I guess
    I need a script to delete all files except if they contain a 1.  I haven't used a forum since way back in the PC mag days.
    Whoops..........I just realized exactly what you were telling me and used your suggestion.  I guess I was trying to do more work than I needed.  I searched for all files with a 1 in the folder and then moved them to a different folder.  Then
    I deleted the rest.  Job done.  Thanks for the help.

  • Just bought a used mac. how can i move files from my pc to the mac?

    How do I migrate my pc files to my mac?

    In addition to following Kappy's advice,  this link can help you also. http://www.apple.com/support/switch101/

  • Windows 7-8.1 Can not change the MAC Address on wifi and cannot load login page in public HotSpot.

    Windows 7-8.1 Can not change the MAC Address on wifi and cannot load login page in public HotSpot.
    Adapter: Ralink RT3070 Chipset wifi adapter
    Tested: os Windows 8.1 Professional
    Hot Spot: 802.11b
    The first problem windows 7-8.1 got IP adress and connect he public HotSpot  but  cannot load login page or any other page. It does not work with it.
    The second problem Wifi canrd/configure/Advandes (No network adress change function).Tested with the default windows driver and the ralink rt 3070 driver the same problem.On windows XP the same function the same driver works perfectly.
    multiple users to have expressed interest in the problem But Microsoft not corrected the problem window7-8.1 10?
    lizardsystems.com/wiki/change_mac_address/faq/change_mac_address_in_windows_7
    blog.technitium.com/2011/05/tmac-issue-with-wireless-network.html
    superuser.com/questions/519189/how-to-change-the-mac-address-in-win-8-to-spoof-a-roku-player-through-a-wifi-spl
    social.technet.microsoft.com/Forums/windows/en-US/59e07df3-471c-499e-ad5f-e7cb507595df/cannot-change-mac-address-in-windows-7-driver-has-option-doesnt-work-neither-does-regedit-ms?forum=w7itpronetworking
    networksteve.com/windows/topic.php/CANNOT_CHANGE_WIRELESS_%28SPOOF%29_MAC_ADDRESS_ON_WINDOWS_7/?TopicId=16810&Posts=1
    On windows XP or linux have a MAC adress Change function  allow 00 mac adress and another normal mac adress range.On windows 8.1 all Mac changer program dont work.This 2,6,A,E on second adress are not vaild Mac adress. You simply can not use normal MAC
    addresses on windows 8.1.When i connect the usb the Pc windows 8.1 recognizes the adapter but the default  driver and the downloaded ralink driver the same problem.On windows xp the current driver works perfectly have (Local Mac Network Adress) funktion
    and works with the 802.11b hot spot.I got the internet my PC and laptop too public HotSpots and another wifi HotSpots if wont work correctly i can not use neither the windows 7,8,8.1 or 10. Many users have expressed interest in the problem more forums.
    The 3. problem im tested in virtualbox the windows 7 and 8.1 on 8.1 (on the blue wifi platform) not show correctly the signal strengh. On windows 7 show this correctly.The windows 7-8.1 Configure/advanced the advanced options on Ralink 3070 the default (windows
    driver) somehow downgraded function is less than for Xp. Configure/advanced the advanced options (needs to be upgraded in the future) because it does not advance but rather regressed.
    Today it is very common these wi-fi technology increasingly used (hotels,Public Hots Spots,Internet coffe,) growing free bublic wifi projects. The wifi funktions on windows  need debugging and modernize.The quality of Wi-Fi is now the operating system
    is now a thing order which is not good then the operating system is unusable.

    Hi,
    For changing the MAC address for Windows 7 is designed with some limitation, we cannot get over it. Thanks for your understanding.
    Under Windows 7, the possible range of spoofed addresses for wireless adapters that can be set is limited.  To be used by Windows 7, a spoofed MAC address should have 0 as a least significant bit (unicast) and 1 as a second least significant
    bit (locally administered) in the second nibble.  Thus possible values for the second nibble are limited to 2, 6, A and E.
    In other words 
    MAC address:  “XY-XX-XX-XX-XX-XX” “X” can be anything hexadecimal.  The hexadecimal “Y”, written in binary format, is  Y:  “kmnp”,  where “p” is the least significant bit; 
    p=0 --> unicast;
    p=1 --> multicast;
    n=0 --> globally assigned MAC;
    n=1 --> locally administered;
    So, actually MAC can be changed  to any combination in which p=0 and n=1;
    “Y” can be 2, 6, A or E.
    So the possible MAC addresses in Windows 7 for wireless adapters:
    X2-XX-XX-XX-XX-XX
    X6-XX-XX-XX-XX-XX
    XA-XX-XX-XX-XX-XX
    XE-XX-XX-XX-XX-XX
    For the wifi hotspot issue, please check this blog to see if it can be helpful.
    Windows 7 Connectivity Problems in Public Hotspots
    http://blogs.technet.com/b/patrickr/archive/2010/07/28/windows-7-connectivity-problems-in-public-hotspots.aspx
    Kate Li
    TechNet Community Support

  • Remotely editing text files in Windows WinRM/PSExec/Powershell/cmd

    Hi!
    How can I remotely edit a text file in Windows?
    I am running and administering a number of Windows 7 workstations and Windows Server 2012 machines. I would like to be able to remotely edit text files on any of these machines. I can connect to any of these machines via psexec or powershell remoting. I
    can also connect via rdp, but for the workstations I would rather not kick the user off unless I absolutely have to.
    For example, we manage state configuration using
    Salt. Local configuration files are stored in C:/salt/conf. I would like to be able to edit these config files on the fly.
    This question on Stack Overflow covers the same topic, but none of the answers are particularly satisfying. Some of the possible solutions
    are:
    Remote Desktop: as I say, I would rather not have to kick a user off their workstation
    Edit a file over a UNC path: this only works for files on a share, and setting up arbitrary shares for quick edits seems like a bad idea.
    Install some manner of ftp or ssh server on all the target computers. This would certainly work, but it is it necessary with WinRM already active? I feel like installing and configuring extra software across all the machines in my organisation would be
    a last resort.
    Edit with a command line editor (e.g. vim, emacs) over a remote powershell session. This doesn't work. I don't understand the technical details, but a powershell remote session isn't interactive in the same way that ssh connections are.
    Edit using powershell's -replace operator, out-file and add-content cmdlets. This works, but is hardly the same as a fully featured text editor.
    Retrieve content from the remote, edit locally, and post back to the remote. This works, and is arguably the best solution I've found. Code sample from SO:
    PS C:\Users\Meredith> Invoke-Command -Session $ps -ScriptBlock {get-content c:/inetpub/myapp/web.config} > web.config
    edit web config
    PS C:\Users\Meredith> get-content web.config | Invoke-Command -Session $ps -ScriptBlock {set-content c:/inetpub/myapp/web.config}
    The last two options are the workflow that I've been using for now. Regex replacement for very simple changes, and copying to local and editing there for more complicated ones. Neither is ideal, but they work. It just feels incredibly old fashioned.
    I'm considering writing a plugin to my editor of choice (vim) to perform the remote fetch and save, to make my workflow a little bit smoother. Before I try that, I just want to know if there's anything that I've missed, or misunderstood.
    Cheers

    What is the "redirector"?
    I posted the same question to Stack Overflow, and was told about administrative shares. I wasn't aware of this, and it's exactly what I wanted. I can open the filetree of a remote machine with the path \\machinename\c$\. Perfectly simple, now that I know
    the answer.

  • Difference in reading a text file in Windows & Unix

    I have a code which is working fine in windows but is stopping after reading the first line of a text file in
    Unix. The code is something like below:-
    declare
    file_handle text_io.file_type; /*running form*/
    filename varchar2(60);
    v_line varchar2(200);
    begin
    message('before fopen');
    filename:=:file_name;message(filename);
    file_handle:=text_io.fopen(filename,'R');
    loop
    begin
    text_io.get_line(file_handle,v_line);
    --:line:=v_line;
    exception
    when no_data_found then
    text_io.fclose(file_handle);
    message('NO MORE DATA IS FOUND ');
    temp:='stop';
    exit;
    when others then
    text_io.fclose(file_handle);
    message('ERROR ');
    exit;
    end;
    mob_no:=substr(v_line,1,10);
    begin
    message(' Mobile NO is '||mob_no);
    message(' Mobile NO is '||mob_no);
    exit when temp='stop';
    end loop;
    commit;
    message('File SUCCESSFULLY LOADED........');
    message('File SUCCESSFULLY LOADED........');
    end;
    Is there any difference in reading a text file in Windows & Unix.
    I hope, my question is clear. Please help in solving the doubt as it is urgent.
    Regards.

    There is no difference in reading a file - you use TEXT_IO in the normal way. However there is of course a difference in the format of text files between Unix and Dos so if you had say transferred your test file from Dos to the Unix box for testing strange things might happen if you had not transferred in ASCII mode.

  • How to load text files in GUI

    plz tell me .. how to load and compare two text files using file popup's . example file i have attached..
    Attachments:
    testW_FF.txt ‏2 KB

    I don't understand whether your question is on how to load text files or how to show them on a panel or how to compare them... or all aspects together!
    The first operation (loading the file) can be accomplished with functions included in the Formatting and I/O Library like OpenFile, ReadFile and so on; with a file like yours even FileToArray could be an option.
    How to show the data on screen is heavily dependent on what you intend to do with them: data can be shown in textboxes, listboxes, tables or graphs so... what do you want to do?
    The same applies with comparison: without additional details is difficult to give you the proper hint.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • I cannot open a pdf file with aole-mail. I can open pdf files from windows explorer. I have associated pdf with adobe reader. My operating system is window

    I cannot open a pdf file with aol e-mail. I went to preferences in Adobe Reader but did not know what to enter for Incoming IMAP and outgoing SMTP. I can open pdf files from windows explorer as  I have associated .pdf files with adobe reader. My operating system is windows 7.
    When I try to open the pdf file within aol e-mail I get a message: 'Your security settings do not allow this file to be downloaded'.  I have not changed my security settings (Tools, Internet Options, security).

    Or http://helpx.adobe.com/acrobat/kb/pdf-browser-plugin-configuration.html

  • Does anyone know how i can view PDF files using Galaxy Note 2?

    Does anyone know how i can view PDF files using Galaxy Note 2?
    This is what i have been doing;
    I click on the file i wish to view (via a portal)
    this file goes to notification widget (i drag down screen)
    notification/message says download complete
    i click on notification/message
    nows it says complete action using (here i only have 2 icon options 1= DB Text Editor 2 = HTML Viewer)
    I have installed Adobe Reader.

    Can you confirm if the downloaded file is a pdf file, that is it ends with .pdf?

  • Windows Easy Transfer can't transfer files from Windows Vista or Windows XP

    I'm running a English Windows Vista Ultimate and just bought a
    ENGLISH Windows 8.1. I've downloaded the WET for Windows vista and tried to complete the second portion of the transfer by specifying the saved .MIG file WET created. Then I got the error message: "Windows Easy Transfer can't transfer
    files from Windows Vista or Windows XP".
    The truth is, Microsoft was too busy integrating special effects to it's operating system and claimed it as fully polished instead of making sure built-in tools were worth using.
    Another harsh reality is that THERE IS NO WAY TO TRANSFER a file from Windows Vista to Windows 8. That's because engineers didn't even bother to make that possibility happen. Just Google: "Transfer from windows vista to windows 8" and you'll see
    there are no relevant Microsoft web page about this.
    Worse, Microsoft is giving excuses. To solve this issues, they came with a toolbox of fake scenarios in order to confuse clients even further, while they know damn well the Windows Easy Transfer is NOT EASY and certainly in multiple cases
    DOES NOT TRANSFER jack to begin with.

    I somewhat agree with you.
    Trying to transfer from 7 to 8.1 and although it looks like the "7" side of the equation is working, the "8" side isn't.
    "7" is trying to connect to "8" but "8.1" is being just plain stupid.
    Not even sure why the MIG file step is even necessary if all I want to do is transfer one file between two machines.  Said file is really BIG, or i'd just use my network, and the "8.1" rig doesn't have a dvd reader...
    Per the MIG step... my file again, is big... I'd need to "mig" this file just to send it? Can't even get to the step where I'd mig-it and if i did, how long would that take?
    So this is what progress is all about... geez... gimmie a NULL MODEM CABLE !!!

  • Is it possible to import a Fixed Text file that does not have a header?

    I'm trying to import a Fixed Text file through Import Manager, but the text file I am receiving does not have a header on it (the first row is valid data). When I try importing this, Import Manager uses the first row of data as the headings. Is there any way to turn this off and tell Import Manager there is no header data in the file?
    Thanks!

    Hi Ryan ,ur requirement can be met only when u import the file as ODBC .for this follow the below steps.
    1)Go to control panel,in ur settings,select administrative tools
    2) In that select DATA SOURCE(ODBC ).
    3)Go to SYSTEM DSN tab select tab .
    4)Select ur file type MICROSOFT TEST DRIVER (.txt,.csv)
    5)Double click on "Import DSN" and in the blank give the name of DATA SOURCE NAME any name u want to give.
    6)Uncheck the use current directory box and select the directory ur file is it will automatically show ur source file select it and click ok.
    7) Now when u import ur file as ODBC give the name of ur DATA source name which u have given and it will show ur file in the source preview itself .
    In  this way u can import ur file as ODBC.
    Hope this may help u.
    Regards
    Ankit

  • Flash wont load text file

    Hi Everyone,
    I have a flash program which reads some data in from a text
    file and stores them in a list box. The problem im having is that
    on one of my computers it works fine, however on the second
    computer, there is no log entry in the
    windows\system32\logfiles\w3svc1 file which indicates that the text
    file has been opened.
    So from this i assume that there is something wrong with
    flash and IIS. Is there someway to turn off the IIS in flash so it
    wont load a "
    http://localhost/test.txt"
    file?
    I think I may have accidentally switched off an option but i
    have no idea where this would have been. Any help would be great.
    Thanks

    hi all
    at last i found the way to load text file in to the textArea
    it's like
    <mx:Script>
    <![CDATA[
    private function loadText():void {
    var l:URLLoader = new URLLoader(new URLRequest('2.txt'))
    l.addEventListener(Event.COMPLETE, finishLoading);
    public function finishLoading(evt:Event):void {
    var myData:String =new String(evt.target.data)
    txtBox.text=myData;
    ]]>
    </mx:Script>
    this should works because it's work with me
    enjoy the code
    Sanji

  • How to check authorizations of a text file in windows server while accesing

    hi,
    I have to access a text file from windows server like windows NT/2003 in to SAP server through report program.
    While accessing the file i have to check the authorization of that file access users of windows.And i have to read it into SAP report program.
    Regards,
    Shankar.

    hi,
    Thanks for Immediate reply.
    i have to check this at level of windows login details i.e user name  and file acces permissions to login user.  through abap coding i have to check it  weather the windows login user having authorizations to access that file are not. If he is having authorization to access then that text file has to read in to ABAP report program and it has to be used in program. other wise it has to be raise an error message
    if provide some example with code...it will be very help full to clear my problem.
    Thanks & Regards,
    Shankar.
    Edited by: Shankar  Reddy Chamala on Aug 26, 2008 8:55 AM

  • "Windows cannot access the specified device,path, or file.You may not have the appropiate permission

    We subscribe to a service called "Vault" which provies its documents in encrypted PDFs using the etd format. As well as Digitial Editions we have Acrobat Reader 9 installed on our PCs (Windows XP,SP2). When a user tries to download any of the documents they are seeing the following error:
    "Windows cannot access the specified device,path, or file.You may not have the appropiate permissions to access the item."
    However, if they open Digitial Edtions (or have had it open at some point in the past) before they download the document it opens without any problems. We use ZEN works to manage our PCs, and we use something called Dynamic Local User (DLU) which means that when a students logs into a PC the user's local Windows account is created on the fly, and then when they log out it is then deleted. This means that they are effectively using Digitial Edtions for the first time everytime they log into a PC.
    As anyone else seen the above error? Also, is there a way of stopping it? What does Digital Editions do the first time it is opened? Are there registry keys that we can add, which emulates the opening of Digital Editions so it doesn't have to be opened first before we can download the Vault documents?
    Any advice/tips would be most welcome.

    Hi
    Some required information are needed for us to help you.
    Hi NabeelOmer,
    We wonder if you have taken any action such as system restore after this issue occurred.
    You might also try this command to restore your access control list.
    Run this command to navigate to the drive letter, example is D
    D:
    To reset all permissions, run this command
    icacls * /reset /t /c /q
    Visual Studio is a very invasive program and which provides the ability to enumerate projects and solutions for system, user should never try uninstalling it manually without any guidance.
    Visual Studio made changes for your whole system, if the file has been moved or deleted this error would occur.
    Since you mentioned that you get this error almost everywhere even in control panel. We suggest you repair/reinstall your Visual Studio first and check if it could be fixed.
    How to: Repair Visual Studio
    https://msdn.microsoft.com/en-us/library/aa983433%28v=vs.90%29.aspx?f=255&MSPPError=-2147217396
    Regards
    D. Wu

  • Import Text Files Into Apple Notes?

    Hello,
    Is there a way for me to automate importing text files into Apple Notes? I can certainly do this manually via copy/paste, but have over 700 files to transfer.
    Peace,
    Dr. Z.

    Automator is Apple's simple way to do tasks like this, but Notes app doesn't have any actions for this so I assume you need to use Applescript to do this. Double check Automator  - I am on 10.9 & maybe 10.10 added support for Notes in Automator? Enter 'Note' in the search field to see if Automator can make new Notes.
    There is an example for making notes at…
    http://www.macosxautomation.com/applescript/notes/04.html
    See the "Create New Stylized Note" script <- click script icon to download it, copy & paste seems to fail because of how the browser displays characters.
    You would need to adapt that script to import from the text files.
    I'm not sure you really want to do that anyway - Notes app has such poor support that putting serious data into it looks like a mistake - how difficult will it be to export data when Apple eventually abandon it? It seems like a toy app to me for new iPhone users, it;s unclear if it will ever be able to compete with other options. There are third party apps to export from Notes.app, but why rely on third parties? A notes app should allow you to import & export your data!
    Notational Velocity seems like a better choice…
    http://notational.net/
    It will handle notes as text files if you desire, so you can store them in Dropbox if you want. You can also set it to sync to Simplenote on iOS.
    http://simplenote.com/
    If you need images within notes or text styling you could use Evernote or one of the many other notes apps.
    Sorry to sound so negative on Notes.app, it's OK but I don't think its the best place to put over 700 notes.

Maybe you are looking for