1

I have a textbox where I put the name of a file that contains the forward-slash character '/' When I grab the text from the textbox the '/' is automatically replaced with '\' and it obviously can't find the file, for example:

I write C:\Users\Temp\my/file.txt I get C:\Users\Temp\my\file.txt

So, instead of opening "my/file.txt", it searches for a directory "my" which contains "file.txt"

How can I solve this?

3
  • 2
    Please show a minimal reproducible example. Commented Apr 19, 2021 at 12:25
  • 2
    Just curious: On what O/S is my/file.txt a valid filename? (I.e. where the / isn't a directory specifier.) Commented Apr 19, 2021 at 12:31
  • 2
    / is invalid in NTFS file names. It's a directory specifier on Unix, Linux, MacOS. Where did you find a file named my/file.txt in the first place? Commented Apr 19, 2021 at 12:41

1 Answer 1

2

If you're using Windows (which I assume you are, given the paths in your example), then / is an invalid character for a filename:

Example

The easiest solution here would be to remove the slash from the filename as this is likely to cause further issues down the line.

Sign up to request clarification or add additional context in comments.

1 Comment

I didn't think of that, thanks! I know it seems dumb but I have to make a mod to an app that already works and somehow that didn't came to my mind

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.