Copy and paste
Serpentin
-
Anonymous user -
Anonymous user -
Hello, I'm a beginner in programming and I'm simply looking to copy and paste a .txt file in the same directory. It must be so simple that I can't find an explicit result on the internet, so I'm open to any help, thank you!
2 answers
-
Hello,
not necessarily simple or complicated.
First of all, you need to think about what the program should do.
When you're a beginner, you can compare humans with the tasks to be filled by a program (afterwards, you know that you need to reason differently and develop the right instincts/algorithms).
So how can you go about copying a file?
1_first, you need to find the file
2_next, open it and read it; otherwise, you won't have access to its content
3_then transfer the content into a new file/create the new file.
It's not simple or complicated; it's just that you're not thinking clearly:
In order to copy something, you first need to read (or rather open) it.
So your program's essential role is to open a file and then read (the program) its content.
Then, if you want to copy its content, you need to create another file.
You probably haven't searched much, because if you can't find a clear result, I have dozens by typing "read file in c#"
https://www.qwant.com/?q=lire fichier txt en c%23
In short, break down the tasks to understand what needs to be done by the program.
Your example/question clearly shows that you're forgetting some data:
What is a file?
What is its content?
How do you create a new file?
You may know this, but a computer, and especially a program, does not reason. It cannot imagine a concept; it's a calculator.
So if you give it false or incomplete data: (I want to copy-paste: it doesn’t know what "copy-paste" means, and even less so for a file; it has a vague idea, but it's up to you to define the treatment of it: open the specified file and read it).
To learn and progress, you must accept that you are ignorant, so drop the preconceived idea that copying and pasting is simple and accept that you are 'ignorant'. (I am not calling you ignorant; I am highlighting that to learn, you must accept that you do not know).
For us humans, we might think of a combination of keys or accessing the menu with a right-click, but a computer is incapable of thinking.
A program consists of performing each necessary step; however, you do not consider the steps in your question: it will be difficult to get an appropriate answer or explain something that is vague for you to a machine that cannot think at all.
Note:
When you do research, you have several ways to approach it:
either be exhaustive and state specific points as I indicated or, on the contrary, do a general search to arrive at the precise point. However, you have not done either of those. This does not mean you are not intelligent; it just means you have not searched enough or correctly (which amounts to the same).
For example, by typing 'file c#' into a search, you can easily see the different possibilities and methods associated with files and their handling.
https://www.qwant.com/?q=fichier c%23 -
Hello
Even though I generally agree with Tartrin, there is no need to open a file to copy it. The classes dedicated to file manipulation know how to copy or move a file regardless of its content.
That said, knowing and using these classes is part of the basics to acquire in C#.
So, I think you are making the classic mistake of the self-taught learner (I did it too in my time) which is to learn randomly.
Well, know that it doesn't work; there is always a moment when you find yourself stuck because you made a beginner's mistake.
The best advice I can give you is to set your project aside for a few days while you take an online course.
It won't make you an expert coder, but it will give you the foundation necessary for your learning.
For C#, Tahé's course is very good https://tahe.developpez.com/dotnet/csharp/
--
When I was little, the Dead Sea was only sick.
George Burns