如果您想了解计算目录中所有文件的记录的相关知识,那么本文是一篇不可错过的文章,我们将对计算目录中所有文件的记录时间进行全面详尽的解释,并且为您提供关于C#实现Zip压缩目录中所有文件的方法、djang
如果您想了解计算目录中所有文件的记录的相关知识,那么本文是一篇不可错过的文章,我们将对计算目录中所有文件的记录时间进行全面详尽的解释,并且为您提供关于C#实现Zip压缩目录中所有文件的方法、django – Nginx,用于提供目录中所有文件的SImple配置以及其中的所有目录、Groovy:获取目录中所有文件的列表(递归)、Java程序合并目录中所有文件的内容的有价值的信息。
本文目录一览:- 计算目录中所有文件的记录(计算目录中所有文件的记录时间)
- C#实现Zip压缩目录中所有文件的方法
- django – Nginx,用于提供目录中所有文件的SImple配置以及其中的所有目录
- Groovy:获取目录中所有文件的列表(递归)
- Java程序合并目录中所有文件的内容
计算目录中所有文件的记录(计算目录中所有文件的记录时间)
如何解决计算目录中所有文件的记录?
因此,情况如下: 我每天都会收到一堆文件,我想计算目录中每个文件(不包括标题)中的记录数,并在CSV文件中显示计数以及文件名。
我正在使用以下命令,但无法以csv格式编写。我知道我已经接近解决方案了。但是还不够紧密。请帮忙。
find . -type f \( -name "${FILE_NAME}" \) | xargs wc -l | aaj -F "," ''{print $1-1,"\011",$2}'' >> count.csv
FILE_NAME是我用来存储文件名格式的变量(= XYZ * {DATE} *。dat)
我的主要挑战是使用CSV格式,因为我想通过电子邮件发送该文件,以便用户可以在MS Excel中打开它。我能够输出制表符分隔的文本文件。但是我更喜欢CSV。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
C#实现Zip压缩目录中所有文件的方法
本文实例讲述了C#实现Zip压缩目录中所有文件的方法。分享给大家供大家参考。具体实现方法如下:
using System; using System.IO; using System.Collections; using System.IO.Compression; using System.Collections.Generic; class FolderZip { private const long BUFFER_SIZE = 20480; static void main(string[] args) { string sourcepath=@"C:\tmp"; Queue<FileSystemInfo> Folders = new Queue<FileSystemInfo>(new DirectoryInfo(sourcepath).GetFileSystemInfos()); string copytopath = @"D:\temp"; copytopath = (copytopath.LastIndexOf(Path.DirectorySeparatorChar) == copytopath.Length - 1) ? copytopath : copytopath+Path.DirectorySeparatorChar + Path.GetFileName(sourcepath); Directory.CreateDirectory(copytopath); while (Folders.Count > 0) { FileSystemInfo atom = Folders.Dequeue(); FileInfo sourcefile = atom as FileInfo; if (sourcefile == null) { DirectoryInfo directory = atom as DirectoryInfo; Directory.CreateDirectory(directory.FullName.Replace(sourcepath,copytopath)); foreach (FileSystemInfo nextatom in directory.GetFileSystemInfos()) Folders.Enqueue(nextatom); } else { string sourcefilename = sourcefile.FullName; string zipfilename = sourcefile.FullName.Replace(sourcepath,copytopath) + ".zip"; if (!File.Exists(zipfilename)) { FileStream sourceStream = null; FileStream destinationStream = null; GZipStream compressedStream = null; try { // Read the bytes from the source file into a byte array sourceStream = new FileStream(sourcefilename,FileMode.Open,FileAccess.Read,FileShare.Read); // Open the FileStream to write to destinationStream = new FileStream(zipfilename,FileMode.OpenorCreate,FileAccess.Write); // Create a compression stream pointing to the destiantion stream compressedStream = new DeflateStream(destinationStream,CompressionMode.Compress,true); long bufferSize = sourceStream.Length < BUFFER_SIZE ? sourceStream.Length : BUFFER_SIZE; byte[] buffer = new byte[bufferSize]; int bytesRead = 0; long bytesWritten = 0; while ((bytesRead = sourceStream.Read(buffer,buffer.Length)) != 0) { compressedStream.Write(buffer,bytesRead); bytesWritten += bufferSize; } } catch (ApplicationException) { continue; } finally { // Make sure we allways close all streams if (sourceStream != null) sourceStream.Close(); if (compressedStream != null) compressedStream.Close(); if (destinationStream != null) destinationStream.Close(); } } } } } }
希望本文所述对大家的C#程序设计有所帮助。
django – Nginx,用于提供目录中所有文件的SImple配置以及其中的所有目录
我正在寻找一个简单的配置来提供特定文件夹中的所有文件和目录.
更确切地说,我试图在pinax / static_media /文件夹和/ media /文件夹中提供所有内容,因为它使用相同的URL,并且最好自动索引所有内容.
顺便说一句,我运行python manage.py build_media – 所以所有静态内容都在< project_name> / site_media / static下
我正在使用的当前配置:
server {
listen 80;
server_name QuadraPaper;
access_log /home/gdev/Projects/QuardaPaper/access_log.log;
location ^*/site_media/*$
{
autoindex on;
access_log off;
root /home/gdev/Projects/QuardaPaper/site_media;
}
location /media/ {
autoindex on;
root /home/gdev/Projects/QuardaPaper/media/;
}
例如,来自各个站点的所有不同配置指令确实让我很困惑
How to serve all existing static files directly with NGINX, but proxy the rest to a backend server.
http://coffeecode.net/archives/200-Using-nginx-to-serve-static-content-with-Evergreen.html
https://serverfault.com/q/46315/91723
http://wiki.nginx.org/Pitfalls
http://pinaxproject.com/docs/0.7/media/#ref-media-devel
环境信息:
>在VirtualBox上运行Xubuntu 10.04
> Nginx 1.1.4
> pinax 0.72
> django 1.0.4
> fastcgi通过Nginx运行django
解决方法:
我找到了答案,我觉得这很简单.
必须设置一次根目录并使用子目录作为位置
server {
listen 80;
server_name QuadraPaper;
access_log /home/gdev/Projects/QuardaPaper/access_log.log;
root /home/gdev/Projects/QuardaPaper;
location /site_media/ {
autoindex on;
access_log off;
}
location /media/ {
autoindex on;
}
}
我得到了一个线索
Nginx doesn’t serve static
Groovy:获取目录中所有文件的列表(递归)
我试图得到(不打印,这很容易)一个目录中的文件列表,它的子目录。
我试过了:
def folder = "C:\\DevEnv\\Projects\\Generic"; def baseDir = new File(folder); files = baseDir.listFiles();
但我只得到了dirs。我也试过
def files = []; def processFileClosure = { println "working on ${it.canonicalPath}: " files.add (it.canonicalPath); } baseDir.eachFileRecurse(FileType.FILES,processFileClosure);
但是“文件”在闭包的范围内不被识别。
如何获得列表?
解决方法
import groovy.io.FileType def list = [] def dir = new File("path_to_parent_dir") dir.eachFileRecurse (FileType.FILES) { file -> list << file }
然后列表变量包含给定目录及其子目录的所有文件(java.io.File):
list.each { println it.path }
Java程序合并目录中所有文件的内容
要合并目录中所有文件的内容,Java代码如下 −
示例
import java.io.*; public class Demo{ public static void main(String[] args) throws IOException{ File my_dir = new File("path to place where file is generated"); PrintWriter my_writer = new PrintWriter("The .txt where changes are stored"); String[] file_names = my_dir.list(); for (String file_names : fileNames){ System.out.println("Content read from " + file_names); File my_file = new File(my_dir, file_names); BufferedReader my_reader = new BufferedReader(new FileReader(my_file)); my_writer.println("The file contains " + file_names); String my_line = my_reader.readLine(); while (my_line != null){ my_writer.println(my_line); my_line = my_reader.readLine(); } my_writer.flush(); } System.out.println("All data from files have been read and " + my_dir.getName() + "merged"); } }
输出
All file contents will be merged into a single text file.
名为 Demo 的类包含 main 函数。将创建一个新文件类型及其位置 需要创建新文件的位置作为参数传递给它。
创建一个 PrintWriter 实例,并将目录中存在的文件名存储在字符串中 array。文件名被迭代,并使用BufferedReader实例进行读取。无论读取到什么内容,都会保留 写入新文件并存储。写入器也被冲洗,因此不会留下任何残留物。
以上就是Java程序合并目录中所有文件的内容的详细内容,更多请关注php中文网其它相关文章!
关于计算目录中所有文件的记录和计算目录中所有文件的记录时间的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于C#实现Zip压缩目录中所有文件的方法、django – Nginx,用于提供目录中所有文件的SImple配置以及其中的所有目录、Groovy:获取目录中所有文件的列表(递归)、Java程序合并目录中所有文件的内容等相关内容,可以在本站寻找。
本文标签: