Reputation: 149
I am trying to write a text file to a folder named folder_01/01/2000
My code is the following:
set folder_path to " >> ~/Desktop/folder_01/01/2000"
do shell script "echo " & "text" & folder_path & "textfile" & ".txt"
I get an error saying that the directory doesn't exist. I believe that is happening because I have backslashes in the name of the folder and it meshes up the the path.
When I remove the backslashes it works properly.
Is there a way to write to the folder with the backslashes?
Upvotes: 0
Views: 58
Reputation: 6102
As @vadian stated, you ought not to used slashes (/
) in your file and folder names, for this very reason. It not only confuses you as a user, but it can confuse a shell, which can lead to anomalous or catastrophic results during file processing.
But, to answer your question, the way to reference that folder in your script is to replace the slashes (/
) in the folder name with colons (:
):
set folder_path to " >> ~/Desktop/folder_01:01:2000/"
do shell script "echo " & "text" & folder_path & "textfile" & ".txt"
(PS. You also omitted a slash at the end of the folder name, which is needed to form part of the path to the text file. I've inserted it above.)
Upvotes: 2
Reputation: 285180
You are talking about slashes (/
) not backslashes (\
).
Slashes are path separators in macOS. You are discouraged from using slashes in file names
Upvotes: 0