Tag Info

Hot answers tagged

76

Preamble I spent some time and designed and implemented a tiny framework to deal with this problem, over the last two days. Here is what I've got. The main ideas will involve implementing a simple key-value store in Mathematica based on a file system, heavy use and automatic generation of UpValues, some OOP - inspired ideas, Compress, and a few other ...


22

Maybe something like Select[FileNames["*", "", Infinity], DirectoryQ]


21

Your problem is that you've got a slight misunderstanding of the different types of items that ReadList can read. That's OK, it can be a little confusing. To begin with: String, Number, Expression, etc. are not sub-types of Record. They are all separate types with their own rules for how they are read. The RecordSeparators option is only applied to ...


18

I don't like to answer my own question, but to give an idea of what an answer might be here's my first stab at this (in the form of a toolbar), just try running UtilityDock[] and click "Branch" after saving it. (Note: I think the best answer wouldn't make use of a toolbar) UtilityDock := (c = Cell[BoxData[ ToBoxes[Grid[{{Item[ Row[{" ...


17

If your notebook is in the top directory, you can use Import[FileNameJoin[{NotebookDirectory[], "path", "to", "your", "file.xls"}] where the string is the relative path from that directory. If your notebook is elsewhere in the directory tree and you want to set paths relative to a different directory, then you could define a global $ParentDirectory and ...


16

I think you can use Names["Global`*"] to get the name: a = RandomReal[{0, 1}, 10]; SetDirectory[$TemporaryDirectory]; DumpSave["1.mx", a]; Quit[] SetDirectory[$TemporaryDirectory]; << 1.mx Names["Global`*"] (*{"a"}*)


15

There are several configuration files that you can use to load functionality at startup. They have the form ($BaseDirectory | $UserBaseDirectory)/(Kernel | FrontEnd)/init.m where $BaseDirectory is for every user on the system and $UserBaseDirectory is for you along and Kernel or FrontEnd specifies what you are configuring. In fact, a lot of the ...


14

Sure, use FileNames: FileNames["myfile.doc", {"C:\\"}, Infinity] This finds any files named myfile.doc on drive C:. Add other drives as needed to the list: {"C:\\", "D:\\", . . .} File names can be given as literal strings, StringExpression string patterns, RegularExpression objects, or abbreviated string patterns. A method to abort the search ...


14

If the notebook is saved, you can use: NotebookFileName[EvaluationNotebook[]] or simply (thanks to @rm -rf) NotebookFileName[] and if it's just the file's name you are after: NotebookFileName[] // FileNameSplit // Last Alternatively, even for unsaved notebooks, try: CurrentValue[EvaluationNotebook[], {"NotebookFileName"}]


13

I believe it does work, just not how you expect. :-) From the documentation for PutAppend: Note that there are no quotation marks around filename in the first line. It is not made particularly clear but you can use this syntax with >>>: Range[10] >>> file.txt Which outputs to a file named file.txt directly. This is a special and ...


12

If I'm not mistaken the second asterisk in your line FileNames["*",{"*"},Infinity] should be replaced with the location of the directory you want to look in. In case of the directory where your notebook lives in this would be: FileNames["*", {NotebookDirectory[]}, Infinity] or, for the current directory, this would be: FileNames["*", {Directory[]}, ...


12

Here are some commands I ran on my machine to generate a few files, and give them some history: touch foo1 foo2 foo3 foo4 touch foo3 cat foo2 Here are the files: files = FileNames["foo*"] (* ==> {"foo1", "foo2", "foo3", "foo4"} *) The most recently changed file: SortBy[files, FileDate] // Last (* ==> "foo3" *) The newest file: SortBy[files, ...


12

If you use Import/Export to load/save .mx files, instead of DumpSave, then the variable does not get embedded in the file, and you can assign it to any variable of choice in the new session. x = RandomReal[1, {100, 100}]; Export["~/tmp.mx", x]; y = Import["~/tmp.mx"]; x == y (* True *)


12

Since Mathematica is written in the C programming language, it is likely that any file-system status operation is doing nothing more than calling C's built-in functions. In this case, that would be stat. So let's test what stat does on Windows. According to the C language documentation, stat is given the name of something in the file system, and returns a ...


11

Maybe, displaying the bytecount of every output expression in tooltips or status area: $Post = Tooltip[#, ByteCount[#]] & or $Post = StatusArea[#, ByteCount[#]] & To delete all generated cells in the notebook, evaluate FrontEndExecute[FrontEndToken["DeleteGeneratedCells"]] or FrontEndTokenExecute["DeleteGeneratedCells"] To delete all ...


11

From the help OpenWrite["file"] open an output stream to a file, wiping out the previous contents of the file ... it's gone, you deleted it :


10

You are looking for FileDate.


10

With $UserBaseDirectory/Kernel/init.m the most obvious place to put code which should be autoloaded has been mentioned. But I think it might be worth mentioning that there is also the Autoload directory within $UserBaseDirectory where you can put any package file or package directory and those will automatically be loaded at startup. For the purpose ...


9

On Mac OS 10.7 just holding down the Option key while you drag works.


9

On Linux, you can combine your favorite version control system (Git in this example) with inotify to automatically commit your changes to the repository whenever your .nb file is saved. Create a Git repository, and save your notebook (say notebook.nb) in the repository. Use inotifywait to automatically run git commit notebook.nb --allow-empty-message -m '' ...


9

As a software developer, I'd suggest a non-mathematica solution to the general problem of versioning. Use a version control system, such as git, that supports text files (i.e. notebooks). If you both (1) use an external version control system, where you explicitly commit after any "interesting" change, and (2) setting the default configuration to ...


9

I haven't tried it myself but you can install the LiveWeb plugin for PowerPoint which allows to embed a live webpage into a slide. Now you should prepare an HTML page with emdedded CDF object (here you can find old instructions how to do this, but probably there is easier way now) and embed it into a PowerPoint slide. People say that it works surprisingly ...


8

Functionality you are looking for is included in Wolfram Player Pro. Detailed functionality difference relative to Free Wolfram CDF Player and Mathematica is listed here: CDF Player, Player Pro, and Mathematica Features Comparison Chart If including your data in CDF is possible in your case then 1) This blog (2nd example) shows simplest case of ...


8

I recommend an external command approach. On Windows this looks like this: command = "!dir \"" <> Directory[] <> "\" /A:D /S /B"; ReadList[command, String] This can be many times faster than the Select - FileNames method. Select[ FileNames["*", "C:\\Data & Images", Infinity], DirectoryQ ] // Length // AbsoluteTiming {6.7413856, ...


8

SystemDialogInput["FileSave"] will do this for you. Something like fileName = SystemDialogInput["FileSave"] If[fileName != $Canceled, Export[fileName, myData]] should do the whole trick. The fire extension determines the type of export (if MMA knows it and supports it). Preselecting a directory path and filtering allowable file extensions can be done as ...


8

The following is a slight modification to @amr's code. It shows a directory tree using TreeForm[], with a button at each vertex. When the button is pressed, it opens a dialog with the list of the files contained in that directory. ellipsizeMax = 8; ellipsize[str_] := If[StringLength[str] > ellipsizeMax, StringTake[str, ellipsizeMax] <> ...


8

You can't. You can combine CDFs and content generated by other tools on web pages, though. From Frequently Asked Questions about the Computable Document Format (CDF) (Wolfram Research): Do CDFs plug in to Microsoft Office documents or PDFs? Currently, the CDF Player plugin only supports web browsers. We are exploring the same capabilities for a ...


8

The number 2045 is suspicious. Add three to it to include stdin, stdout, and stderr, and you get 2048, which I suspect is total number of file descriptors available to you. I conclude your problem is caused by eating up all the available file descriptors. This is usually caused by doing too many file opens without doing any file closings to return some file ...


8

The problem has nothing to do with OpenWrite. You never Close the stream you open in your call to Read. Read, unlike ReadList, does not automatically close a stream (file, pipe, etc.) that's given as its first argument string. (That's because the purpose of Read is to be able to read from the same source in pieces, unlike ReadList which does it all at ...


7

Amending the file directly would indeed require something like .Net. If you were willing to consider an import-export roundtrip but with a spreadsheet like interface in Mathematica, then something like this might work: rawdata = (Import["myspreadsheet.xlsx"][[2]]); (* where 2 is the number of the worksheet you want to use *) newdata = TableView[rawdata] ...



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