# Save with an object value in file name

**URL:** <https://discourse.julialang.org/t/save-with-an-object-value-in-file-name/76110>\
**Category:** New to Julia\
**Tags:** jld\
**Created:** [February 9, 2022, 6:59pm UTC](https://discourse.julialang.org/t/save-with-an-object-value-in-file-name/76110 "2022-02-09T18:59:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jisutich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jisutich/32/33342_2.png) [@jisutich](https://discourse.julialang.org/u/jisutich)\
**Post date:** [February 9, 2022, 6:59pm UTC](https://discourse.julialang.org/t/save-with-an-object-value-in-file-name/76110/1 "2022-02-09T18:59:35Z")

</div>

Hi guys:

I am using the package `JLD` to save objects. How to add the value of some parameters in the file name? For example, if I have a parameter `a =0.5`, I want the value of `a` to show up in the file name so I can remember what this file represents in the future. I tried the string format like in python but I failed. Thanks.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [February 9, 2022, 7:06pm UTC](https://discourse.julialang.org/t/save-with-an-object-value-in-file-name/76110/2 "2022-02-09T19:06:36Z")

</div>

[https://docs.julialang.org/en/v1/manual/strings/#string-interpolation](https://docs.julialang.org/en/v1/manual/strings/#string-interpolation)

```julia
julia> a = 0.5
0.5

julia> filename = "saved_file_a=$a.jld"
"saved_file_a=0.5.jld"

```

---

<div class="post-metadata">

**Author:** ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)\
**Post date:** [February 10, 2022, 1:00pm UTC](https://discourse.julialang.org/t/save-with-an-object-value-in-file-name/76110/3 "2022-02-10T13:00:25Z")

</div>

If you’re on Windows, you can serialize your parameters (or anything else) to an Extended Attributes Stream like this

```julia
using Serialization

params = Dict(:a=>5, :b=>7)

open("results.txt", "w") do io 
    println(io, "Here are my results")
end

open("results.txt:Strml:\$DATA", "w") do io 
    serialize(io, params)
end

open("results.txt", "r") do io 
    println(read(io, String))
end

open("results.txt:Strml:\$DATA", "r") do io 
    println(deserialize(io))
end

```

This code will output

```julia
Here are my results

Dict(:a => 5, :b => 7)

```

This Stream will stay with your file and be preserved by Windows tools such as copy.

`dir /r` reveals them in directory listings

```julia
$ dir /r results.txt
 10/02/2022 12:56 20 results.txt
                                 36 results.txt:Strml:$DATA

```

I can’t find an easy way to do that on Linux, without shelling out to `setattr`

So you could, of course, `serialize` to a separate file e.g. `results.txt.meta`

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [February 10, 2022, 4:31pm UTC](https://discourse.julialang.org/t/save-with-an-object-value-in-file-name/76110/4 "2022-02-10T16:31:29Z")

</div>

Make sure to read the docstring of `Serialization.serialize` if you consider saving your data that way, so you know about its limitations and can determine whether those are fine for your use case.
