㈠ 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 ++编译器是忽略空行的,空白行可以改善代码的可读性和结构。