filenames

How do I retrieve all filenames in a directory?

*爱你&永不变心* 提交于 2019-12-03 15:57:31
问题 How do I retrieve all filenames matching a pattern in a directory? I tried this but it returns the full path instead of the filename. Directory.GetFiles (path, "*.txt") Do I have to manually crop the directory path off of the result? It's easy but maybe there is an even simpler solution :) 回答1: foreach (string s in Directory.GetFiles(path, "*.txt").Select(Path.GetFileName)) Console.WriteLine(s); 回答2: Assuming you're using C#, the DirectoryInfo class will be of more use to you: DirectoryInfo

handling filename* parameters with spaces via RFC 5987 results in '+' in filenames

痞子三分冷 提交于 2019-12-03 14:25:14
I have some legacy code I am dealing with (so no I can't just use a URL with an encoded filename component) that allows a user to download a file from our website. Since our filenames are often in many different languages they are all stored as UTF-8. I wrote some code to handle the RFC5987 conversion to a proper filename* parameter. This works great until I have a filename with non-ascii characters and spaces. Per RFC, the space character is not part of attr_char so it gets encoded as %20. I have new versions of Chrome as well as Firefox and they are all converting to %20 to + on download. I

RegEx pattern in glob function

心不动则不痛 提交于 2019-12-03 13:32:41
I recive a filename in a function. I want to return all files similar to this file (by filename) from other directory. I wrote this: $thumbDir = $this->files_path.'thumbs/'; $toglob = $thumbDir.pathinfo($name, PATHINFO_FILENAME ).'_[0-9]+\x[0-9]+_thb.'.pathinfo($name, PATHINFO_EXTENSION); foreach (glob($toglob) as $key => $value) { echo $value; } But it doesn't work. I search files which their filename is: oldFileName_[one or more digits]x[one or more digits]_thb.oldFileNameExtension I will be very grateful if someone help me with this :) Sam glob() is really a quasi-regex engine. From a

How to find duplicate filenames (recursively) in a given directory? BASH

隐身守侯 提交于 2019-12-03 13:03:29
问题 I need to find every duplicate filenames in a given dir tree. I dont know, what dir tree user will give as a script argument, so I dont know the directory hierarchy. I tried this: #!/bin/sh find -type f | while IFS= read vo do echo `basename "$vo"` done but thats not really what I want. It finds only one duplicate and then ends, even, if there are more duplicate filenames, also - it doesnt print a whole path (prints only a filename) and duplicate count. I wanted to do something similar to

SPLFileInfo: get filename without extension

ⅰ亾dé卋堺 提交于 2019-12-03 11:36:00
I'm accessing a number of files in the SPLFileInfo object. I see a way to get the path, filename, and even extension of the file. Is there a way to get the filename without extension? Here's the code I've been working with but I'm hoping to get something more elegant. Is there an out of the box solution? $file = new SplFileInfo("path/to/file.txt.zip"); echo 'basename: '.$file->getBasename(); echo PHP_EOL; echo 'filename: '.$file->getFilename(); echo PHP_EOL; echo 'extension: '.$file->getExtension(); echo PHP_EOL; echo 'basename w/o extension: '.$file->getBasename('.'.$file->getExtension()); >

Move files to directories based on first part of filename?

房东的猫 提交于 2019-12-03 09:06:53
问题 I have several thousand ebooks that need to be organized on a headless linux server running bash through SSH. All of the ebooks are thankfully named with one of 2 conventions. AuthorFirstName AuthorLastName - Book Title.pdf AuthorFirstName AuthorLastName - Book Series #inSeries - Book Title.pdf What I would like to do is to move all of the books into an organized system such as: `DestinationDirectory/FirstLetterOfAuthorFirstName/Author Full Name/pdf's` e.g. the following books Andrew Weiner -

CarrierWave: Create the same, unique filename for all versioned files

♀尐吖头ヾ 提交于 2019-12-03 06:53:34
问题 Before I go into detail I'll get right to the point: has anyone figured out a way to get Carrierwave to save files with their names as a timestamp or any arbitrary string that is unique to each file? By default Carrierwave saves each file and its alternate versions in its own directory (named after the model ID number). I'm not a fan of this because instead of one directory with 1,000, for the sake of using a large round number, files (in my case pictures) in it we get one directory with 1

.htm or .html extension - which one is correct and what is different?

不羁岁月 提交于 2019-12-03 06:11:17
问题 When I save a file with an .htm or .html extension, which one is correct and what is different? 回答1: Neither is wrong, it's a matter of preference. Traditionally, MS software uses htm by default, and *nix prefers html . As oded pointed out below, the .htm tradition was carried over from win 3.xx, where file extensions were limited to three characters. 回答2: Mainly, the number of characters is different. ".htm" smells of Microsoft operating systems where the file system historically limited

How do I retrieve all filenames in a directory?

匆匆过客 提交于 2019-12-03 06:10:19
How do I retrieve all filenames matching a pattern in a directory? I tried this but it returns the full path instead of the filename. Directory.GetFiles (path, "*.txt") Do I have to manually crop the directory path off of the result? It's easy but maybe there is an even simpler solution :) foreach (string s in Directory.GetFiles(path, "*.txt").Select(Path.GetFileName)) Console.WriteLine(s); Assuming you're using C#, the DirectoryInfo class will be of more use to you: DirectoryInfo directory = new DirectoryInfo(path); FileInfo[] files = directory.GetFiles("*.txt"); The FileInfo class contains a

PHP Dynamic include based on current file path

a 夏天 提交于 2019-12-03 06:03:15
I want to find a method to include some files based on the current file path.. for example: I have "website.com/templates/name1/index.php", this "index.php should be a unique file that I will use in many different directories on different depths, so I want to make the code universal so I don't need to change anything inside this file.. So if this "index.php" is located in " website.com /templates/name1/index.php" than it should include the file located here: " website.com/content /templates/name1/content.php" another example: " website.com /templates/name2/index.php" than it should include the