導航:首頁 > 文件教程 > c拷貝文件夾

c拷貝文件夾

發布時間:2025-05-16 19:11:35

① 用c語言如何把文件復制到指定文件夾

不妨可以定義一個指針
比如char *p="";
scanf("%s",p);
fp=fopen(p,"r");
這樣就可以通過scanf自己輸路徑了
思路就是fp=fopen("abc.txt","r");
等價於char *p="abc.txt";fp=fopen(p,"r");
裡面可能還有些技術上專的問題,稍屬加修改一下,應該沒問題吧

② c盤C:\Users,用戶文件夾怎麼能轉到D盤使用

Windows 10系統中有個名為Users(也可能顯示為「用戶」)的默認文件夾,該文件夾主要用於存放用戶的資料,如:文檔、圖片、視頻、收藏夾、桌面、軟體的設置或數據等。users文件夾默認是在系統所在分區的根目錄下,如果把這個文件夾轉移到非系統所在其他盤符,不僅可以為系統所在的分區(一般為C盤)節省出一些空間,還可以在重裝系統時避免用戶文件的丟失。


5.重啟電腦並進入系統,users文件夾已成功轉移到D盤下。

③ WinForm(C#)復制文件夾(文件)問題

文件復制:File.Copy(fnsrc, fndes, true);第三個參數表示是否替代同名文件;
文件夾復制可以遍歷文件夾進行復制。
剛出爐,熱的。。。。建立一個form,一個按鈕下實現的,測試通過:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace CopyDirectory
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
CopyDirectory("c:\\downloads","d:\\");
}

/// <summary>
/// 拷貝文件夾
///By Wang Hw www.pegete.com.cn
/// </summary>
/// <param name="srcdir"></param>
/// <param name="desdir"></param>
private void CopyDirectory(string srcdir, string desdir)
{
string folderName = srcdir.Substring(srcdir.LastIndexOf("\\")+1);

string desfolderdir = desdir +"\\"+ folderName;

if (desdir.LastIndexOf("\\") == (desdir.Length - 1))
{
desfolderdir = desdir + folderName;
}
string[] filenames = Directory.GetFileSystemEntries(srcdir);

foreach (string file in filenames)// 遍歷所有的文件和目錄
{
if (Directory.Exists(file))// 先當作目錄處理如果存在這個目錄就遞歸Copy該目錄下面的文件
{

string currentdir = desfolderdir + "\\" + file.Substring(file.LastIndexOf("\\") + 1);
if (!Directory.Exists(currentdir))
{
Directory.CreateDirectory(currentdir);
}

CopyDirectory(file, desfolderdir);
}

else // 否則直接文件
{
string srcfileName = file.Substring(file.LastIndexOf("\\")+1);

srcfileName = desfolderdir + "\\" + srcfileName;

if (!Directory.Exists(desfolderdir))
{
Directory.CreateDirectory(desfolderdir);
}

File.Copy(file, srcfileName);
}
}//foreach
}//function end

}
}

④ 怎樣用C語言將文件復制另外的文件夾

有兩種方式可以實抄現復制:
一、自襲行編寫函數,實現復制。
演算法流程如下:
1
以讀的方式打開源文件,以寫的方式打開目標文件;
2
每次讀一個位元組,並寫到目標文件中,直到達到文件結尾為止;
3
關閉兩個文件。
二、調用系統命令。
stdlib.h中的system函數,可以執行系統命令行支持的命令。
int
system(char
*cmd);
調用時就是執行cmd中的指令。
1
對於windows,就是執行dos命令,可以調用
system("
/Y
src_file
target_dir");
其中src_file為源文件,而target_dir就是目標文件夾。
2
對於Linux,需要執行shell命令cp,如下
system("cp
src_file
target_dir");

閱讀全文

與c拷貝文件夾相關的資料

熱點內容
linux文件狀態標志 瀏覽:861
java讀取子文件 瀏覽:1
怎麼隱藏文件手機 瀏覽:479
編程軟體哪個需要錢 瀏覽:875
如何看自己的ie版本 瀏覽:492
2008r2用戶文件夾路徑 瀏覽:755
winzip文件壓縮成多個小文件 瀏覽:562
勒索病毒文件是哪個 瀏覽:855
群聊機器人代碼 瀏覽:728
用什麼充電app最便宜 瀏覽:531
jspif語句 瀏覽:896
你刪除的照片會在哪個文件夾 瀏覽:518
編程如何設置 瀏覽:393
微信jssdk分享qq空間 瀏覽:840
修改ipadid密碼忘記了怎麼辦 瀏覽:938
紙質文件拍攝視頻 瀏覽:560
今天的疫情數據怎麼樣 瀏覽:491
出國旅行不會英語需要什麼app 瀏覽:351
移動機用聯通資料庫 瀏覽:710
啟動器配置文件丟失怎麼能 瀏覽:686

友情鏈接