Message Boards Message Boards

0
|
4205 Views
|
2 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Export with StringForm gives "..not a valid file specification"

Posted 3 years ago

Hello,

I was trying to export data to files numbered as file001.txt, file002.txt, ...

Do[
Export[
    StringForm["C:\\Users\\Potter\\Desktop\\file``.txt", 
        NumberForm[
            i, 3, NumberPadding -> {"0", "0"}, NumberSigns -> {"", ""}
        ]
    ], data[[i]], "Table"
],
{i,1,5}
]

StringForm generates the file names properly, but Export gives and error of "..not a valid file specification." What do I need to do?

Thank you.

POSTED BY: Yeso Alde
2 Replies
Posted 5 months ago

Wrapping with ToString[] also seems to work.

Do[Export[
  ToString[
   StringForm["file``.txt", 
    NumberForm[i, 3, NumberPadding -> {"0", "0"}, 
     NumberSigns -> {"", ""}]]], data[[i]], "Table"], {i, 1, 5}]
POSTED BY: Junghyeon Park
Posted 3 years ago

The problem is that StringForm is not a String. Generate the file names like this.

Do[Print["C:\\Users\\Potter\\Desktop\\file" <> IntegerString[i, 10, 3] <> ".txt"], {i, 5}]

(*
C:\Users\Potter\Desktop\file001.txt
C:\Users\Potter\Desktop\file002.txt
C:\Users\Potter\Desktop\file003.txt
C:\Users\Potter\Desktop\file004.txt
C:\Users\Potter\Desktop\file005.txt
*)
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract