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
119 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 ...
user avatar
  • 225k
50 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,...
user avatar
  • 225k
44 votes
5 answers
21k 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 ...
user avatar
  • 1,455
15 votes
2 answers
548 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 (...
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 ...
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]...
user avatar
  • 30.5k
27 votes
4 answers
5k 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 ...
user avatar
  • 4,889
12 votes
5 answers
1k 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 ...
user avatar
  • 4,647
31 votes
4 answers
8k views

Relative paths for portable notebooks in Mathematica

I cannot find how to use relative paths in Mathematica. My directory structure is simple. ...
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 ...
user avatar
  • 10.7k
22 votes
1 answer
578 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 ...
user avatar
52 votes
1 answer
4k 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?...
user avatar
  • 11.3k
12 votes
2 answers
765 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 ...
user avatar
  • 10.6k
19 votes
2 answers
647 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 ...
user avatar
  • 7,439
19 votes
2 answers
526 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 ...
user avatar
  • 1,491
10 votes
1 answer
800 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 ...
user avatar
  • 15.8k
11 votes
4 answers
511 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 ...
user avatar
  • 133k
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 ...
user avatar
  • 1,533
3 votes
2 answers
801 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,\...
user avatar
  • 33
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 ...
user avatar
  • 32.5k
26 votes
1 answer
499 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 ...
user avatar
  • 1,857
24 votes
1 answer
591 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 ...
user avatar
  • 264k
7 votes
4 answers
1k 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 ...
user avatar
  • 5,210
5 votes
1 answer
338 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. ...
user avatar
  • 7,439
22 votes
1 answer
3k 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 ...
user avatar
  • 39.4k
6 votes
1 answer
78 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 ...
user avatar
  • 29.7k
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 ...
user avatar
  • 5,059
17 votes
3 answers
900 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 ...
user avatar
  • 68.8k
20 votes
6 answers
3k 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, ...
user avatar
  • 1,011
8 votes
3 answers
26k 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 ...
user avatar
  • 2,470
11 votes
0 answers
283 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 ...
user avatar
  • 1,523
9 votes
1 answer
302 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 ...
user avatar
  • 133k
14 votes
3 answers
372 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 ...
user avatar
  • 11.3k
9 votes
2 answers
305 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 ...
user avatar
  • 91
7 votes
4 answers
923 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 ...
user avatar
6 votes
0 answers
298 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 ...
user avatar
5 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 ...
user avatar
  • 888
14 votes
3 answers
326 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 <...
user avatar
1 vote
2 answers
937 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 ...
user avatar
9 votes
2 answers
179 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 ...
user avatar
  • 106k
6 votes
1 answer
853 views

How do I directly read the Nth byte from a binary file?

I have a very large binary file (several hundred GB) which I would like to process using Mathematica. I only need to process a few bytes of this file at a time, and I know in advance which bytes I ...
user avatar
  • 2,297
5 votes
2 answers
239 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 ...
user avatar
  • 784
4 votes
1 answer
121 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....
user avatar
  • 15.8k
2 votes
2 answers
207 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 : "...
user avatar
2 votes
1 answer
192 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:...
user avatar
  • 894
4 votes
1 answer
222 views

Where can I permanently modify Directory[]?

First I set SetDirectory["F:\\learning_mma"];Directory[](*ok,success*) and then I quite the kernel: Quit[] an then ...
user avatar
  • 6,676
3 votes
2 answers
1k views

Processing all files in a folder automatically

I have a lot of files in a folder that needs to be process through a function that I have written in Mathematica. I need help writing a code that would process all the files automatically. ...
user avatar
11 votes
1 answer
311 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, ...
user avatar
  • 4,888
10 votes
1 answer
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 ...
user avatar
9 votes
3 answers
1k views

Better random (unique) file name

In order to avoid conflict with file names produced by some code running in multiple instances of Mathematica I append the date and a random string at the end hoping to create a unique filename. The ...
user avatar
  • 3,603