List All Files in a Directory using Dot Net Zip? - compact-framework

Is there anyway in Dot Net Zip that I can use to list all the names of files in a specific directory? For example, i can specify Directory1 and get File3 and File4 etc
ZipFile
-------
File1
File2
Directory1
File3
File4
Directory2
File5
File6
ZipFile object has only Entries, Entries Sorted, and Entries File Names...
Anyone?, Cheeso? :)

No, and yes. There is no EntriesInDirectory collection. However, it's a simple matter of string comparison to select entries that "belong" in a particular directory.
In LINQ it looks like this:
var selection = from e in zip.Entries
where e.FileName.StartsWith(directoryName)
select e;
In a for loop, it looks like this:
var list = new List<ZipEntry>();
foreach (var e in zip.Entries) {
if (e.FileName.StartsWith(directoryName)) {
list.Add(e);
}
}
EDIT
You may have to do conversions for case sensitivity. On Windows, case is not meaningful in file names.
Further Explanation: the zip format doesn't treat a directory entry in the zip file as a container. There is no container relationship between directory entries and file entries. The only way to tell if a file entry "belongs in" a particular directory is to examine the full name of the file entry. If the name of the entry starts with the name of the directory in question, then the entry is "in" the directory.

Related

Rename txt file name in Pentaho

I have a problem. I have created a few files txt in directory.
file1.txt
file2.txt
file3.txt
Next I writing name files to file txt: filenames.txt with step: Shell.
ls D:\test\prep\ > filename.txt
I have there all name files which are in directory. My filenames.txt looks like this:
file1.txt
file2.txt
file3.txt
Later I read the values from the file in step Text file input and value which I get I writing to step copy to result.
Next I use get rows from result and transformation_executor.
I would like get a new name file for each file with step get rows from result: instead file1.txt I want file.txt. I think that in transformation_executor I must have TABLE_INPUT with name with step get rows from result but I don't know what's next.
Any have idea?
You need to use below step/way, if you want to read a directory files based on another configuration file (which contain the directory files information).
Step-1:
Step-2:
Step-3:
You can found the all transformation/Job from HERE
Please let me know if its ok with you.

Get file name from SAP Data service

I'm unable to read file name from data services which contain date_time format, I can read date but time can be variable, I've tried with *.csv on file name(s) property for flat file, but this for static file name.
Example: File_20180520_200003.csv, File_20180519_192503.csv, etc.
My script:
$Filename= 'File_'|| to_char(sysdate()-1, 'YYYYMMDD')|| '_'|| '*.csv';
I want to find a solution to read the 6 digits (any number) *.
Finally, I've found a solution by using
$Csv = word(exec('cmd','dir /b [$Filename]*.csv',8),2) ;
on the flat file (file name property), I've added $Csv
It works fine.

Comparing a .TTL file to a CSV file and extract "similar" results into a new file

I have a large CSV file that is filled with millions of different lines of which each have the following format:
/resource/example
Now I also have a .TTL file in which each line possibly has the exact same text. Now I want to extract every single line from that .TTL file containing the same text as my current CSV file into a new CSV file.
I think this is possible using grep but that is a linux command and I am very, very inexperienced with that. Is it possible to do this in Windows? I could write a Python script that compares the two files, but since both files contain millions of lines that would literally take days to execute I think. Could anyone point me in the right direction on how to do this?
Thanks in advance! :)
Edit:
Example line from .TTL file:
<nl.dbpedia.org/resource/Algoritme>; <purl.org/dc/terms/subject>; <nl.dbpedia.org/resource/Categorie:Algoritme>; .
Example line from current CSV file:
/resource/algoritme
So with these two example lines it should export the line from the .TTL file into a new CSV file.
Using GNU awk. First read the CSV and hash it to a. Then compare each entry in a against each row in the TTL file:
$ awk 'BEGIN { IGNORECASE = 1 } # ignoring the case
NR==FNR { a[$1]; next } # hash csv to a hash
{
for(i in a) # each entry in a
if($0 ~ i) { # check against every record of ttl
print # if match, output matched ttl record
next # and skip to next ttl record
}
}' file.csv file.ttl
<nl.dbpedia.org/resource/Algoritme>; <purl.org/dc/terms/subject>; <nl.dbpedia.org/resource/Categorie:Algoritme>; .
Depending on the sizes of files it might be slow and maybe could be made faster but not based on info offered in the OP.

Removing files from a directory based on file names in another file

I have a directory which contains multiple file (~1000) with names in the form of ABC.txt, ABC.1.txt, ABC.2.txt, XYZ.txt, XYZ.1.txt and so on.. I want to consider these names based on the first index if we split them by .. For example then names will be read as ABC XYZ and so on.. Then I want to remove those files for which these first index does not exist in an other (reference file). Given the file names mentioned above, let's say my other (reference file) only contains 1 name and that is XYZ. So the files that will be kept in the directory will be XYZ.txt and XYZ.1.txt and everything else which does not have the exact prefix as XYZ will be removed. I said exact because it might happen that there will be a file with name XYZA.txt, so there should be an exact match in order to keep that file.
Can anybody help me with this. Thank you very much.
EDIT: One directory contains all the files: ABC.txt, ABC.1.txt, ABC.2.txt, XYZ.txt, XYZ.1.txt and the reference file is in another directory as file name reference.txt and is a one-column file containing other directory's file (prefix)names as ABC, XYZ, CDE etc..
try
for f in *.*;
do if grep -qF "${f%%.*}" file;
then echo "skip $f";
else echo "rm $f"; fi;
done
searches all files with a dot in file name, extract the prefix until the first dot, compare literally in the file with not to be deleted names, and echo the rm file command. Make sure your file with names doesn't have a dot, otherwise it will be removed as well.
if looks fine remove echo before rm.

rename file in bourne shell

I am trying to write a bourne-shell script that takes a directory as a parameter and look for images named ixxx.a and rename them to ixxx_a.img where "xxx means the extension number for exemple image files would be named i001.a , i002.a ,i003.a ...)
here what I tried
mv $1/f[0-9][0-9][0-9].a $1/f[0-9][0-9][0-9]_a.img
but it says that the DEST is not a directory.
Any help would be much appreciated. Thanks.
for i in $1/f[0-9][0-9][0-9].a; do
mv $i ${i%.a}_a.img
done
However, this does not consider blank spaces in the file/folder names. In this case you'd have to use while so you get one file name per line (see below for bonus). There are probably dozens of other ways, including rename.
find $1 -maxdepth 1 -type f -name "f[0-9][0-9][0-9].a"|while read i; do
mv "$i" "${i%.a}_a.img"
done
Edit: Perhaps I should explain what I did there. It's called string substitution and the main use cases are these for a variable var:
# Get first two characters
${var:0:2}
# Remove shortest rear-anchored pattern - this one would give the directory name of a file, for example
${var%/*}
# Remove longest rear-anchored pattern
${var%%/*}
# Remove shortest front-anchored pattern - this in particular removes a leading slash
${var#/}
# Remove longest front-anchored pattern - this would remove all but the base name of a file given its path
# Replace a by b
${var//a/b}
${var##*/}
For more see the man page.