Menu

Cannot open files if path has spaces...

2006-03-22
2012-11-13
  • Nobody/Anonymous

    I am having problems double clicking to open files with notepad++ if the path and/or the file name contain spaces. If notepad++ is NOT open, the text file will open fine. If notepad++ is already open, then I get an err saying that npp "could not open" the file. However, I am still able to successfully open such files by "draging-and-dropping" the file onto the notepad++ window. I am using v3.5, but I have noticed this issue with v3.4 as well.

    Example:
    c:\path\name\here\text file name here.txt

    If notepad++ is NOT already open, it will open the file just fine. But if notepad++ IS already open, then it will give the following errors:

    Could not open file "c:\path\name\here\text".
    Could not open file "c:\path\name\here\file".
    Could not open file "c:\path\name\here\name".
    Could not open file "c:\path\name\here\here.txt".

    If the path also included spaces (example below), it would respond like this:

    c:\generic\path name here\text file name here.txt

    Could not open file "c:\generic\path".
    Could not open file "c:\installed path\notepad++\name".
    Could not open file "c:\installed path\notepad++\here\text".
    Could not open file "c:\installed path\notepad++\file".
    Could not open file "c:\installed path\notepad++\name".
    Could not open file "c:\installed path\notepad++\here.txt".

    Yes, it switched from the directory in which I had tried to open the text file, to the directory into which notepad++ was installed. It should also be noted that I attempted to follow the instructions here [ http://sourceforge.net/forum/message.php?msg_id=3561292 ] by adding these strings to a batch file in the notepad++ installation directory and executing:

    set npp_path="%cd%"
    reg add HKLM\Software\Notepad++ /v "" /d %npp_path% /f
    set npp_path=

    Yeah, it still doesn't work.

    Because some programs call for notepad.exe directly instead of using file association I made a batch file (a while back) to replace the original notepad.exe file with notepad++ version. The problem with that is that notepad++ must know were certain files are located or it will not load.

    What I did was gather all of those files into an empty directory along with the installed executable for notepad++. I renamed the notepad++ executable to "notepad.exe" and then ran the batch file. Here is the batch file that I use after I install notepad++ on a new system:

    ren %windir%\ServicePackFiles\i386\notepad.exe.backup
    ren %windir%\system32\dllcache\notepad.exe notepad.exe.backup
    ren %windir%\system32\notepad.exe notepad.exe.backup
    ren %windir%\notepad.exe notepad.exe.backup

    copy notepad.exe %windir%\ServicePackFiles\i386
    copy notepad.exe %windir%\dllcache
    copy notepad.exe %windir%\system32
    copy notepad.exe %windir%\

    copy langs.xml %windir%\ServicePackFiles\i386
    copy langs.xml %windir%\dllcache
    copy langs.xml %windir%\system32
    copy langs.xml %windir%\

    copy SciLexer.dll %windir%\ServicePackFiles\i386
    copy SciLexer.dll %windir%\dllcache
    copy SciLexer.dll %windir%\system32
    copy SciLexer.dll %windir%\

    copy stylers.xml %windir%\ServicePackFiles\i386
    copy stylers.xml %windir%\dllcache
    copy stylers.xml %windir%\system32
    copy stylers.xml %windir%\

    copy config.xml %windir%\ServicePackFiles\i386
    copy config.xml %windir%\dllcache
    copy config.xml %windir%\system32
    copy config.xml %windir%\

    If the batch file does not find a directory (ServicePackFiles for example) it moves on to the next line of the batch file.

    Any ideas on how I can correct this "Cannot open file" issue? Or is it a bug in the software? Any help much appreciated.

     
    • Nobody/Anonymous

      Forgot to mention that when the error messages switched to the installation directory the program was correctly able to parse the space in that part of the path.

      "\installed path\" = "\Program Files\"

       
    • Paulius

      Paulius - 2006-03-22

      I don't know. I'm opening files with spaces in their path and names - i have no problems!

      By the way, i read your post twice - sounds like a nice way to mess up your computer...

       
    • Nobody/Anonymous

      I agree, without the proper caution this batch file has the potential to really screw your system. However, as it is setup here for *notepad.exe*, it is safe enough and easily undone if need be. It renames the original file for just such a purpose.

      As for the problem I'm having with NPP, guess I need to keep looking for an alternative.

       
    • Nobody/Anonymous

      What I ended doing is replacing MS notepad.exe with the program win32pad (renamed of course). It is not multi-tabbed like NPP, but at least when a program calls notepad.exe directly it will open up something better than the stupid MS default notepad.

      This solution was not my first choice, but it is better than nothing.

       
      • Tony McNamara

        Tony McNamara - 2006-08-02

        This is a real problem.  Repro case is - set a path to notepad++.exe.  From inside a path including spaces (in my case, the emulator path of J2ME for Motorola, but any path with spaces), try to edit the file using just the filename - e.g. notepad++ foo.bar.  That will fail, as it bangs into the canonical pathname.

        Okay, so what to do about it? 

        I only downloaded the code a few minutes ago - spent five minutes figuring I might be able to find it.  I think the problem is in RunDlg.cpp, void Command::extractArgs(char *cmd2Exec, char *args, const char *cmdEntier)

            for ( ; i < int(strlen(cmdEntier)) ; i++)
            {
                if (cmdEntier[i] != ' ')
                    cmd2Exec[i] = cmdEntier[i];
                else
                    break;
        Note that this breaks the args on every space.  A better solution would be contextual argument parsing.  Since we know that all non-filename args begin with a dash (ref http://notepad-plus.sourceforge.net/uk/cmdLine-HOWTO.php ) and the filename comes last, the first apparent argument not beginning with a dash THROUGH TO THE END OF LINE should be assumed to comprise a single filename.

        Make sense?

         
        • TheDutchJewel

          TheDutchJewel - 2007-01-09

          And still this problem exist...

          If this disadvantage could be repaired, Notepad++ would be the best text editor for me. I'm wondering why this bug still exist. Any chance that this bug will be solved soon? Would be great.

           
          • TheDutchJewel

            TheDutchJewel - 2007-01-29

            The problem still exists in v4.0 final...

             
          • TheDutchJewel

            TheDutchJewel - 2007-01-09

            I see I can't edit my previous post...

            Well, this problem exist only for me when creating a new file with Shift-F4 in Total Commander. Editing a file in a dir with spaces in the name is not a problem. So as a workaround I created an empty batch file "0.bat" (0=zero) with this line:

            @echo off >%1

            Than in TC I simply type e.g. "0 filename.txt", after which I press F4 on the empty filename.txt file. This works good.

            But because this problem doesn't exist with other text editors, I hope the Notepad++ programmers will fix this problem.

             
          • Nobody/Anonymous

            Hello,
            i just came across the problem with spaces in path.
            The problem is: (suppose i am on commandline inside "c:\path with spaces\&quot;

            If npp is closed and i start "npp info.txt", the file is correctly opened.
            If npp is started and i start "npp info.txt", the debugger shows c:\path with space\info.txt
            as the file to open. It is decoded as multiple files and npp wants to open "c:\path", "with" and so on.

            IMHO the problem is, that it is possible (which is a good feature :-)) to open multiple files on commandline like
            "npp file.1 file.2 file.3". But its still annoying, if it isnt possible to open a file from inside a "spaced" path while npp is running.
            So i hacked a bit inside the source and made some modifications in notepad_plus.cpp and FileNameStringSplitter.h.
            The change in filenamestringsplitter is:
            case ' ' :
              if (isInsideQuotes)
                {
                str[i] = *pStr;
                i++;
                }
               else
               {   
                 str[i] = '\0';
                 if ( PathFileExists((const char *)str))
                {
                  if (str[0])
                  _fileNames.push_back(std::string(str));
                i = 0;
                }
                else
                {
                str[i] = *pStr;
                i++;
            }
            }
            Read: If the splitter sees a space, it tests if "str" contains an existing file. If not, it simply assumes, its a space in a path. This is not the salavage for all "spaced" path problems but it solves the most annoying for me.

            Another change i made is in notepad_plus.cpp:

            case WM_COPYDATA :
                    {
            [...]
                int ln = pCopyData->dwData >> 8;
               if (PathFileExists((const char *)pCopyData->lpData))
               {
                 doOpen((const char *)pCopyData->lpData);
                           
                 if (lt != L_TXT)
                _pEditView->setCurrentDocType(lt);
                if (ln > 0)
               _pEditView->execute(SCI_GOTOLINE, ln-1);
            }
            else
            {   
               FileNameStringSplitter fnss((const char *)pCopyData->lpData);
               char *pFn = NULL;
               for (int i = 0 ; i < fnss.size() ; i++)
            [...]

            The original code sends the pCopyData->lpData unseen to FileNameSplitter. My change is to check with PathFileExists if the passed data is a existing file.

            As already stated, this is not the salavage for all "spaced" path problems but it solves the most annoying for me.

            I really like npp! Great program.

            Cheers

             
        • Nobody/Anonymous

          Hello,

          I haven't checked the code, but I do see a potential error here:

          or ( ; i < int(strlen(cmdEntier)) ; i++)
          {
          if (cmdEntier[i] != ' ')
          cmd2Exec[i] = cmdEntier[i];
          else
          break;

          In this snippet of code "i" is NOT initialised.

          Of course if "i" is initialised by the declaration it is OK.

          Best regards,
          Karsten

           
          • Don HO

            Don HO - 2007-01-12

            > In this snippet of code "i" is NOT initialised.

            Sure, it is. Just the line before the for loop :

            int i = 0;
            for ( ; i < int(strlen(cmdEntier)) ; i++)
            {
              if (cmdEntier[i] != ' ')
                cmd2Exec[i] = cmdEntier[i];
              else
                break;
            }

            Don

             
    • Nobody/Anonymous

      Following will help:

      notepad++.exe "c:\path\name\here\text file name here.txt"

      Regards
      Jens