㈠ C語言怎麼選擇保存的文件夾啊
在c語言中因為它不能識別漢字,所以你所要保存的文件的文件名最好設為英文字母,然後在保存的時候指定你的文件路徑就可以了。
㈡ C++中怎樣將文件保存到指定目錄
指定文件夾地址,然後讀取文件夾內容。
file.h
[cpp]viewplainprint?
#include<string>
#include<vector>
#include<io.h>
/*
*定義於io.h
*1、long_findfirst64i32(constchar*_Filename,struct_finddata64i32_t*_FindData);
*查找第一個_Filename的信息,存儲到結構體_FindData中
*查找成功,返回一個用於繼續查找的句柄(一個唯一的編號)
*查找失敗,返回-1
*
*2、int_findnext64i32(longhandle,struct_finddata64i32_t*fileinfo);
*根據句柄handle查找下一個文件,存放在fileinfo中
*查找成功,返回0
*失敗返回-1
*
*3、ing_findclose(longhandle);
*關閉句柄handle
*成功返回0,
*失敗返回-1
*
*4、struct_finddata64i32_t
*用來存儲文件的各種信息
*struct_finddata64i32_t
*{
*unsignedattrib;
*__time64_ttime_create;//-1forFATfilesystems
*__time64_ttime_access;//-1forFATfilesystems
*__time64_ttime_write;
*_fsize_tsize;
*charname[260];
*};
*unsignedattrib:4個位元組,存儲文件的屬性
*_A_ARCH(存檔)0x20
*_A_SUBDIR(文件夾)0x10
*_A_SYSTEM(系統)0x04
*_A_HIDDEN(隱藏)0x02
*_A_RDONLY(只讀)0x01
*_A_NORMAL(正常)0X00
*以上均是宏,unsignedint,各屬性疊加時進行或運算,如_A_HIDDEN|_A_RDONLY
*
*__time64_ttime_create:文件創建的時間
*__time64_ttime_access:文件最後一次訪問的時間
*__time64_ttime_write:文件最後以此修改的時間
*_fsize_tsize:文件的大小,位元組為單位
*charname[260]:文件名
*/
enumTKFileInfo
{
FILE_EMPTY=-1,//目錄為空
FILE_SUCCESS,//查找成功
};
structfileInfoNode
{
struct_finddata64i32_tfileInfo;
std::stringfileName;
structfileInfoNode*left;
};
typedefstd::vector<std::string>VEC_PATH;
classCTKFile
{
public:
CTKFile();
~CTKFile();
public:
intSearchAllFile(std::stringfilePath,
intlayer,
VEC_PATH&vecPath);
private:
intSaveToLink(structfileInfoNode*&head,
conststd::string&fileName,
conststruct_finddata64i32_t&fileInfo);
voidSaveLinkToFile(structfileInfoNode*head,
std::vector<std::string>&vecPath,
intcounter);
㈢ 在c#中(c/s)如何實現將上傳的文件保存到指定的文件夾
參考一下我寫的上傳的事件,我把保存的路徑配置在web.cofig裡面了,(需要注意的是超過一定的大小4M的話就會發生前台的異常,而且這個異常後台沒辦法捕獲,網上有個傢伙寫的捕獲的異常的方法我試了,根本沒有用):
protected void btnSave_Click(object sender, System.EventArgs e)
{
HttpPostedFile postedFile = fileUploadInput.PostedFile;
String userType = this.ddlUserType.SelectedValue;
if (postedFile!=null)
{
//判斷文件是否小於10Mb
if (postedFile.ContentLength < 10485760)
{
try
{
//上傳文件並指定上傳目錄的路徑
String serverPath = System.Configuration.ConfigurationSettings.AppSettings["ReportPath"];
if(serverPath!=null)
{
String fileFullName = fileUploadInput.PostedFile.FileName;
String fileName = Path.GetFileName(fileFullName);
if(getUserManager().isFileNameExist(fileName))
{
lblMsg.Text = "Upload Failed:File with same name already exists!";
}
else
{
if (!Directory.Exists(serverPath))
{
Directory.CreateDirectory(serverPath);
}
postedFile.SaveAs(serverPath+fileName);
getUserManager().saveFileToDataBase(fileName,userType);
lblMsg.Text = "Upload Successfully!";
}
}
else
{
lblMsg.Text = "Upload Failed: Path not found!";
}
/*
* FileUpLoad1.PostedFile.SaveAs(Server.MapPath("~/Files/")+ FileUpLoad1.FileName);
* 注意->這里為什麼不是:FileUpLoad1.PostedFile.FileName
* 而是:FileUpLoad1.FileName?
* 前者是獲得客戶端完整限定(客戶端完整路徑)名稱
* 後者FileUpLoad1.FileName只獲得文件名.
*/
//當然上傳語句也可以這樣寫(貌似廢話):
//FileUpLoad1.SaveAs(@"D:\"+FileUpLoad1.FileName);
}
catch (Exception ex)
{
lblMsg.Text = "Upload Failed,Exception Occurs:" + ex.Message;
}
}
else
{
lblMsg.Text = "Upload Failed:The size of the file can not exceeded 10MB!";
}
}
else
{
lblMsg.Text = "File not seleced!";
}
}
㈣ 如何用c語言將文件復制到自己想要的文件夾
C語言里的system("");函數可以執行命令行的幾乎所有指令,把命令行輸入的內容作為參數傳入回即可答。復制文件的話 應該是: 源文件 目的路徑。
例如命令行里的 c:\test.txt d:\text.txt,
也就是C語言里的:system(" c:\test.txt d:\text.txt");
或者這樣
char c[50] = " c:\test.txt d:\text.txt";
system(c);
㈤ 用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語言怎麼保存文件到指定的路徑
fp=fopen(filename,"wb");
里的就表示了文件的路徑及文件名,所以要把輸入的文件名和文件路徑拼接起來,計算出這個filename
最好過濾一下別讓路徑和文件名中有非法字元,比如:\/+<>什麼的。
scanf也限制一下長度。
scanf("%19s",filename);
scanf("%19s",path);
參考如下:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fp;
char ch, filename[20], path[20],buffer[40];
printf("Enter the file name: ");
scanf("%s",filename);
printf("Enter the path: ");
scanf("%s",path);
sprintf(buffer, "%s\\%s", path,filename);
printf("\nto end input ,press Ctrl+Z in newline,then ENTER:\n");
if((fp=fopen(buffer,"wt+"))==NULL)
{
printf("no such path, \nstrike any key exit!");
getch();
exit(1);
}
while ((ch=getchar())!=-1) ch=fputc(ch,fp);
fclose(fp);
printf("==================================\n\n");
printf("file path \"%s\" \nfile name \"%s\":\nand its content:\n",path,filename);
fp=fopen(buffer,"rt");
while ((ch=fgetc(fp))!=-1) putchar(ch);
fclose(fp);
return 0;
㈦ C語言 如何創建文件到指定文件夾
C語言創建新文件可用fopen()函數的"w"(寫)方式打開文件,即可。如果文件存在,將會清空現有的文件;如果不存在,則會創建該文件。
若要將文件創建到指定的文件夾下,則,在fopen()函數中的文件名,帶上路徑名就可以了。但,程序如果對該文件夾沒有寫許可權,則fopen()會返回NULL。
參考代碼:
#include<stdio.h>
voidmain()
{
charfilename[100];
charfilepath[100];
charfile[200];
FILE*fp;
printf("inputfilename:");scanf("%s",filename);
printf("inputfilepath:");scanf("%s",filepath);
sprintf(file,"%s/%s",filepath,filename);
fp=fopen(file,"w");
if(fp==NULL)
{
printf("openfile:%serror ",file);
return;
}
fputs("thisisatest!",fp);
fclose(fp);
}
㈧ C語言編的程序怎麼保存到指定文件夾謝謝```
用F10點File,彈出下列框點save出現保存路徑,把noname改為你自己想要的名字(可以是字母,數字)點Enter鍵就可以了。或著用F2也是保存。
㈨ C語言創建文件到指定文件夾
源代碼如下:
#include "stdio.h"
#include "conio.h"
#include "dir.h"
int main()
{
int status;
status=0;
status=mkdir("D:mydir");
printf("status=%d",status);
getch();
return 1;
}
(9)c保存文件到指定路徑擴展閱讀
1、C++提供了許多實用的頭文件,這些頭文件里包含了程專序運行時需要屬用到的一些方法,在上面的程序中就引入了iostream。
2、以#為開頭是告訴編譯器,該行代碼需要預處理。include 是告訴編譯器,需要引入iostream這個頭文件。iostream文件定義了輸入流/輸出流對象。
3、C ++編譯器是忽略空行的,空白行可以改善代碼的可讀性和結構。