Questions tagged [files-and-directories]

Questions on obtaining files and directory structure/information and manipulating the said structure/information, searching/renaming particular files in a directory, etc., in an OS independent manner.

Filter by
Sorted by
Tagged with
121 votes
1 answer
8k views

File-backed lists/variables for handling large data

Background Currently I am working with some large data (most of it generated by Mathematica itself). I usually find it a hassle to do this. For example, I just exported a large amount of data to ...
Szabolcs's user avatar
  • 235k
53 votes
3 answers
2k views

Argument completions for user-defined functions

Mathematica 10 has introduced file name completion for the arguments of certain built-in functions, such as Import, SetDirectory,...
Szabolcs's user avatar
  • 235k
46 votes
6 answers
22k views

How to import all files of a folder at once?

I know how to import one textfile by calling its name filestring = Import["myfile.tex", "Text"]; Then "filestring" is a string with the myfile content. How do ...
Nikolaj-K's user avatar
  • 1,485
15 votes
2 answers
605 views

Infix form of PutAppend ( >>> ) does not work with variable

I'm new to Mathematica, so I suspect this question involves either a misunderstanding involving variables or the usage of >>>. On a webMathematica page (...
Daniel's user avatar
  • 825
17 votes
3 answers
2k views

How to workaround failures with Unicode filepaths?

(Cross-posted on the Wolfram Community, reported to the support as [CASE:3965891].) The Mathematica's Kernel and FrontEnd currently work well with Unicode file/directory paths, but some other ...
Alexey Popkov's user avatar
42 votes
3 answers
2k views

How can I set up a versioning system within a notebook?

Since the Frontend crashes a lot, for important work it would be nice to have the notebook automatically branch and save itself every so many minutes. For instance, commands like StartSavingCopies[5]...
M.R.'s user avatar
  • 31.5k
28 votes
4 answers
6k views

List all the directories under the current one

I feel like I am forgetting something obvious, and will remember or be ashamed as soon as an answer turns up. However, I cannot for the life of me get all of the directories in the current working ...
tkott's user avatar
  • 4,939
12 votes
5 answers
2k views

Searching a phrase in all *.nb files

I have so many *.nb files in a folder. In one of them I have written a phrase, unfortunately I cannot remember that file. I am searching about it and the file in ...
Unbelievable's user avatar
  • 4,847
32 votes
4 answers
9k views

Relative paths for portable notebooks in Mathematica

I cannot find how to use relative paths in Mathematica. My directory structure is simple. ...
Matthew Kemnetz's user avatar
10 votes
1 answer
1k views

Analogue of NotebookDirectory[] for scripts (to get the directory path of my script.m)?

Is there a way to get the script directory from inside a Mathematica script? I want a function analogue to NotebookDirectory[] (which doesn't work for scripts). Is ...
a06e's user avatar
  • 11.4k
22 votes
1 answer
624 views

$Path hijacked by PacletManager?

Summary: Since Mathematica version 6, the PacletManager seems to have engineered an escalating hijack of the $Path variable. Add-on packages need to have a ...
Simon Rochester's user avatar
54 votes
1 answer
5k views

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

In Mathematica 10.x, one now has both .wl Wolfram Language Packages and .m Wolfram Mathematica Packages. What's the difference?...
murray's user avatar
  • 11.9k
19 votes
2 answers
559 views

Mathematica "prelude"

Is there any way to have the functions from a mathematica file be loaded on startup? For example, in this excellent answer, Jens helps me out and gives me some functions for creating legends for ...
Andrew Spott's user avatar
  • 1,581
19 votes
2 answers
988 views

Path Names Longer Than 256 on Windows

Is there a way to work with pathnames that are longer than the typical 256 in Mathematica? For example run the following in Cygwin ...
William's user avatar
  • 7,605
12 votes
2 answers
824 views

Execute code when file is modified

I have a function the takes some time to complete. The function imports data from a .csv, parses it, and plots certain vectors from there. The .csv is constantly being updated from an external ...
kale's user avatar
  • 10.9k
10 votes
1 answer
822 views

Mathematica 10 doesn't support path containing Chinese characters

Bug introduced in 10.0 and fixed in 10.0.2 I tried to import file in Mathematica 10 ( windows 7 system), the path contains some chinese characters. After holding ctrl+shift, and drag the file into ...
matheorem's user avatar
  • 17.1k
11 votes
4 answers
549 views

Handy / flexible directory tree operations

Is there any shorter / more handy / more flexible way to get directory tree as a nested Rules/Associations list? I tried to incorporate ...
Kuba's user avatar
  • 137k
4 votes
1 answer
3k views

How to set default save directory for notebooks?

Based on certain previous questions, I figured that if my NotebookBrowseDirectory looked like this ...
Brian B's user avatar
  • 1,553
3 votes
2 answers
915 views

How can I automatically name files being exported based on input parameters

I have Mathematica notebook that performs some operation say a=2 b=3 c=5 d=4 how do I set the output file after evaluation to be named using the values $2,3,5,\...
Stephen's user avatar
  • 33
26 votes
1 answer
518 views

Tool to locate bloat in a notebook?

In developing a notebook, I often find I have created a very boated file that takes a long time to save. I would like to slim it down. It is usually the result of graphics and images, but they may be ...
abwatson's user avatar
  • 1,919
24 votes
1 answer
606 views

A documented syntax of FileNames doesn't work?

Documentation discrepancy present in 10.3 and fixed in 10.4.1 According to the documentation for FileNames under Details: However when I attempt to use this ...
Mr.Wizard's user avatar
  • 272k
22 votes
1 answer
4k views

How to get the directory of a package?

I have a package that I have placed in the $BaseDirectory\Applications directory so that Needs can find it. I have a logo in ...
Edmund's user avatar
  • 42.3k
14 votes
5 answers
2k views

Using ReadList and Skip to read a file with periodic alternation of useful and useless data

I am trying a read a file that's arranged such that there's alternating set of rows containing data that I don't need and data that I need. So for my case the first n lines in the files are useless to ...
RunnyKine's user avatar
  • 33.1k
8 votes
3 answers
1k views

How to add a trusted path in Mathematica?

I would like to add a trusted a path in the global preferences of Mathematica. When I go to NotebookSecurityOptions, click the tool button for ...
Taiki's user avatar
  • 5,259
7 votes
4 answers
2k views

Cannot find BaseDirectory or UserBaseDirectory in Mac OS El Capitan

I am new to Mac OS, so this might be a silly question, but.... I just searched for $BaseDirectory and $UserBaseDirectory in my ...
magma's user avatar
  • 5,290
6 votes
1 answer
116 views

Trace and TracePrint are slow, How to Trace to a file for speed

Trace and TracePrint generates or prints a list of all expressions used in the evaluation of its argument. For complicated ...
rhermans's user avatar
  • 36.5k
5 votes
1 answer
361 views

Watch File in Directory .NET

How might I watch for a specific file to change in a directory using Mathematica/.NET code? The following works in .NET but fires twice when you change the file. ...
William's user avatar
  • 7,605
20 votes
6 answers
4k views

Determine the Number of Lines in a Text File

I have looked and looked but I do not see a simple efficient way to get Mathematica to return the number of lines in a text file? I thought about reading the file until it returned the EOF marker, ...
Sinistar's user avatar
  • 1,029
17 votes
3 answers
1k views

Visualizing directories

How do I plot the content of a directory and all its subdirectories into infinity using TreeForm? I've tried using a mix of ...
C. E.'s user avatar
  • 70.6k
14 votes
3 answers
408 views

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

I am making a GUI for one of my programs. The program is tasked with opening certain data files containing optical spectroscopy data and then doing things which are unrelated to this question. The ...
LLlAMnYP's user avatar
  • 11.5k
14 votes
3 answers
341 views

What kind of check does DirectoryQ exactly perform?

I'm using Mathematica 9.0.1 on Windows XP and my drive letters are assigned as follows: C: and D: are hard local disks, while <...
mitochondrial's user avatar
11 votes
0 answers
318 views

Creating compiled search TRIE file for argument string completion

I'd like to generate a compiled search TRIE file (like those found in $InstallationDirectory\SystemFiles\FrontEnd\SystemResources\FunctionalFrequency\) to help ...
Rashid's user avatar
  • 1,523
10 votes
3 answers
31k views

How to export data to a plain text file?

I am preparing data used by a command line program. It requires data in a simpliest possible format: value_x1 value_y1 value_x2 value_y2 ... value_xN value_yN ...
Misery's user avatar
  • 2,640
9 votes
2 answers
184 views

Problem with LocalSymbol

Bug introduced in 10.2 and fixed in 11.1 I have found that LocalSymbol will sometimes create and store persistent data in a directory different from and off the ...
m_goldberg's user avatar
  • 108k
9 votes
1 answer
319 views

How to unlock a stylesheet which is not needed anymore by the FrontEnd

Bug introduced in 10.3.0 or earlier and fixed in 11.1 Bug reproduced on Win but not on Mac Reply from WRI Support: [...] This indeed seems to be an issue with the Frontend on Windows and I have ...
Kuba's user avatar
  • 137k
9 votes
2 answers
847 views

What's the fastest way to read a simple numerical list?

I have a large .txt file for which I need to do some data analysis. I've been working on it for a while, and the analysis part has got faster and faster so that most of the evaluation time is now ...
Tofi's user avatar
  • 291
9 votes
2 answers
318 views

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

I'm using Mathematica to control another program (Surface Evolver) through the terminal (ie using StartProcess[]; and ...
Nickel's user avatar
  • 91
7 votes
4 answers
965 views

How to batch rename a directory of files?

I have a directory of files with the pattern: "some_number.some_name.pdf" I want to remove the "some_number." part from all the ...
user4714's user avatar
6 votes
1 answer
1k views

Get the last line from each of a large number of files, transform them, and write all results to a single new file

I have several hundreds of .csv files that are not logically named (contains numbers, characters, and special characters), all stored in a directory. Each file has large but unequal number of rows and ...
brama's user avatar
  • 908
6 votes
0 answers
346 views

How to create TAR archive without top-level folder?

Mathematica has the handy CreateArchive function, which allows you to efficiently create a TAR archive from a directory. However, I see no way of specifying not to ...
Fidel I. Schaposnik's user avatar
5 votes
2 answers
286 views

How to define a function to save a list to a same-name file

I want a convenient way to save lots of intermediate data lists into files, so that next time the files can be imported automatically to homonym list variables in the notebook, without having to ...
Chromatic's user avatar
  • 794
4 votes
1 answer
316 views

Resolve absolute path to Documentation Notebook

We can easily create clickable hyperlinks for Documentation pages like the following: {URL["paclet:ref/Set"], Hyperlink["paclet:ref/Set"]} But ...
Alexey Popkov's user avatar
4 votes
1 answer
131 views

Why does Thread FileDate give an error message?

I tried for example Thread[FileDate[FileNames["new*", "h:\\temp\\", 1]]] It gives FileDate::fstr: File specification {h:\temp\NEWEA7D.tmp,h:\temp\NEWEA7E....
matheorem's user avatar
  • 17.1k
2 votes
2 answers
321 views

Where to place the essential WSTP files in Visual Studio 2019?

I have Visual Studio for C installed in : C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC From https://reference.wolfram.com/language/tutorial/WSTPDeveloperGuide-Windows.html : "...
nilo de roock's user avatar
2 votes
1 answer
255 views

Get (<<) Evaluate File Name

This seems like a simple question due to lack of experience, but I can't seem to find an answer through searching. I am trying to read back a symbol from a DumpSave:...
BenP1192's user avatar
  • 934
1 vote
2 answers
1k views

How to set the relative directory so that they work both in script and in notebook and portable?

Maybe the question is not clear, here I try to state it in more detail: I have a folder named project, for instance. In it I have two folders, one is named ...
an offer can't refuse's user avatar
20 votes
2 answers
399 views

How to find the package file that stores a certain symbol?

Is it possible to figure out in what file a certain packaged symbol lives in (assuming there is no shadowing between multiple identical symbol names)? I would like to have a function that if, given a ...
István Zachar's user avatar
15 votes
1 answer
434 views

Wrong function of NotebookDirectory[] in the 12.1 version

Bug introduced in 12.1.0 and fixed in 12.2.0 (or 12.1.1?) Could anybody help? NotebookDirectory[] function began working wrong in 12.1 (the bug was not present in ...
Alexander's user avatar
  • 151
12 votes
2 answers
1k views

Prevent Export from overwriting files

Export["filepath1",Expression1] works for me, but if filepath1 already exists, it will be overwritten. I'd like ...
user1541776's user avatar
11 votes
1 answer
334 views

How to test if file exists on the front end machine?

When using a remote Mathematica kernel, how can you test if a file exists on the local front end machine? Of course FileExistsQ cannot be used in this scenario, ...
sakra's user avatar
  • 5,120