29 votes

Argument completions for user-defined functions

Before you start using this, be aware that this is all undocumented and unsupported functionality. It may change at any time, it may crash Mathematica, and it may bite you when you least expect it. I ...
  • 229k
23 votes
Accepted

How to get the directory of a package?

FindFile will tell you which file will be loaded when you ask for a particular package with the backtick syntax. DirectoryName ...
  • 229k
21 votes
Accepted

Path Names Longer Than 256 on Windows

With a few rare exceptions, Mathematica is generally unable to work with long path names on Windows. This response presents two strategies to work around this difficulty: extended-length path syntax ...
  • 67.6k
20 votes

What is the difference between a .wl package and a .m package?

As after half a year there is still no answer, here are some very short answers from my comments: the difference is just the file ending as far as I know. if you have installed MATLAB (or another ...
  • 23.2k
17 votes
Accepted

How to check whether the folder is created, and if not, create it?

...
  • 229k
17 votes

How to check whether a .txt file is empty

FileByteCount will give 0 for empty text files and is very fast (0.00003 seconds per file on my machine). ...
  • 12.7k
17 votes

What secrets are hidden away in your init.m and where do you place it? Please help me build the ideal init.m

I am an init.m ascetic. And I doubt after 30+ years of using Mathematica I will change. Everyone else, who wishes to, may proclaim how it is indispensable to their workflow, and I will accept their ...
16 votes
Accepted

Relative Path in Mathematica

If you want to have the parent directory of the current directory, use ParentDirectory[]. The parent directory of your notebook can be found using: ...
16 votes

Can Mathematica edit large binary files in-place?

We can do it straightforward in Java using JLink: ...
  • 6,298
15 votes
Accepted

Prevent Export from overwriting files

Your basic requirement is met with: ...
  • 266k
15 votes

Better random (unique) file name

It might be best to use CreateUUID. CreateUUID[] "73ccc27c-687f-4eca-8214-ceeb8a8b7773" ...
  • 33.7k
13 votes
Accepted

$Path hijacked by PacletManager?

Edit From version 9 PacletInfo.m file requires "Kernel" extension with Context ...
  • 14.8k
13 votes
Accepted

How to return notebook's own file name

You have to add a few extra commands to NotebookFileName to remove the directory. Last@FileNameSplit@NotebookFileName[] Hope ...
  • 40.1k
13 votes
Accepted

Making a Dataset that emulates `ls -tlra`?

Build your own Here I create a Dataset of files, taking advantage of the "Rules" option for ...
  • 31.8k
12 votes
Accepted

Searching a phrase in all *.nb files

Here is a way to search from within mathematica: ...
  • 38.5k
12 votes

Making a Dataset that emulates `ls -tlra`?

Try something like that ...
  • 7,468
12 votes

Implementing a Better Grep Command

Mathematica allows text searching using regular expressions (based on the PCRE library). It would take some work to re-implement the whole grep functionality within ...
12 votes

Wrong function of NotebookDirectory[] in the 12.1 version

This is a certainly a bug. The fix for it is going to be available in the next release (version 12.1.1). In the meantime, perhaps the following workaround code may help ...
  • 25.2k
12 votes
Accepted

How to determine the file type of a .m file?

It's somewhat of a meme that WL has a top-level function for everything, but it's kinda true: ...
  • 19.5k
11 votes

Argument completions for user-defined functions

This can be accomplished with the AddCodeCompletion function in the function repository. Evaluate the following piece of code: ...
  • 69.1k
11 votes

How to return notebook's own file name

No need to go through all the machinations of trimming/applying a cascade of functions, simply: CurrentValue["NotebookFileName"]
11 votes
Accepted

Is there a predecessor to the new command CreateFile?

The new function CreateFile has two main tasks, CreateFile[] - will create a file in the "default area for temporary files on ...
  • 64.8k
11 votes

How can I get a FileNameSetter-like dialog inside my own custom dialog?

Not perfect but a good start. Openers expand/collapse trees but it does not affect the preview pane. Clicking on the directory name does. ...
  • 134k
11 votes

What secrets are hidden away in your init.m and where do you place it? Please help me build the ideal init.m

I tend to put a lot of little functions in my init.m file, functions that take arguments and use module variables. I found that I would now have Global symbols like ...
10 votes

Error when implementing StartProcess[] in loops (Do, While, Table)

The problem is that the stdin stream for each process is being left open and needs to be closed. To demonstrate the issue, we create a single process: ...
  • 67.6k
10 votes
Accepted

why CopyFile cannot overwrite existing file?

Use the OverwriteTarget -> True option. Alas, this is not specified in the documentation. ?? CopyFile gives, among other ...
  • 8,392
10 votes
Accepted

how to get the size of a directory(total size of all files under this directory or its subdir or ...)

There is also a function in the Internal` context (for now) that does that ...
  • 25.2k
10 votes
Accepted

Obtain short path on Windows

Windows Command Line Here is a way using the Windows command line: getShortPathName[path_] := Import["!for %p in (\""~~path~~"\") do @echo %~sp", "Text"] So ...
  • 67.6k
10 votes

Opening Mathematica file in Google drive

If you have a public link, you can follow the answer to this question, and basically just import the data Import[url, "Data"] If you need to authenticate to get ...
  • 31.8k
10 votes
Accepted

Renaming Files with Mathematica

The following method does not require a specific fixed number of digits in the start of file name and does not depend on specific fixed non-numeric separator such as "-". ...

Only top scored, non community-wiki answers of a minimum length are eligible