Copy file to the specified path [C # file operation]

xiaoxiao2021-03-06  46

Copy existing files to new files and do not allow you to override existing files. [C #] Public FileInfo COPYTO (String); Copy existing files to new files, allowing the existing file.

[C #] public fileInfo copyto (string, bool); [c #] copy file to the specified path, allowing the same name of the target file CopyUsing System; use system.io; class test {public static void main () {string path @ @ @ @ @@ "c: /TEMP/Mytest.txt"; string path2 = path "TEMP"; try {// create the file and clean handles. using (filestream fs = file.create (path)} // ensure That The target does not exist. file.delete (path2); // copy the file. file.copy (path, path2); console.writeline ("{0} copied to {1}", PATH, PATH2); /// Try to copy the same file again, which should succeed File.Copy (path, path2, true);. ( ". The second Copy operation succeeded, which was expected") Console.WriteLine;} catch {Console.WriteLine ( "Double Copy Is Not ALOWED, WHICH WAS NOT EXPECTED. ");}}} [c #] COPY TESING SYSTEM; USING SYSTEM.IO; Class Test {public static void main () { String path = @ "c: /temp/mytest.txt"; string path2 = @ "c: /temp/mytest.txt" "temp"; fileinfo fi1 = new fileInfo (path); fileinfo fi2 = new fileInfo (Path2 ); Try {// create the file and clean up handles. Us (filestream fs = fi1.create ()) {} // ensure That Target Does not exist. Fi2.delete (); // copy the file. Fi1 .Copyto (path2); console.writeline ("{0} WAS Copied to {1}.", PATH, PATH2); // Try To Copy It Again, Which Should succeed. Fi1.copyTo (Path2, true);

Console.Writeline ("The Second Copy Operation");} catch {console.writeline ("Double Copying Was Not ALOWED, WHICH IS NOT EXPECTED.");}}} To do this. See Examples in this topic ... Create a text file.

Write the text to the file

Write a text file.

Write the text to the file

Read text files.

Read text from the file

Add text to your file.

Open and attach to log files

File.AppendText fileinfo.appendtext renamed or move files. File.Move fileInfo.moveto deletes the file. File.delete fileinfo.delete copy file. File.copy fileInfo.copy Take the file size. FILEINFO.LENGTH Gets file properties. File.getaTRibutes Set the file properties. File.setttributes determines if the file exists. File.exists read binary.

Read and write data files you just created

Write a binary file.

Read and write data files you just created

Retrieve file extensions. Path.GETEXTension Retrieves the fully qualified path of the file. Path.getFullPath retrieves file names and extensions in the path. Path.GetFileName changes the file extension. Use private void Path.ChangeExtension Progress class CopyWithProgress (string [] filenames) {// Display the ProgressBar control pBar1.Visible = true;. // Set Minimum to 1 to represent the first file being copied pBar1.Minimum = 1.; // set maximum to copy. Pbar1.maximum = filenames.length; // set the initial value of the progressbar. Pbar1.Value = 1; // set the step puttety to a value of 1 to represent Each file being copied. Pbar1.Step = 1; // loop through limited files to copy. for (int x = 1; x <= filenames.length; x ) {// copy the file and increment the programsbar if successful. IF (CopyFile (filenames [x-1]) == true) {// perform the increment on the progressbar. Pbar1.Performstep ();}}}

转载请注明原文地址:https://www.9cbs.com/read-74133.html

New Post(0)