Extract filename and immediate parent path

Started by ODYSSEUS, November 21, 2021, 05:13:11 PM

Previous topic - Next topic

ODYSSEUS

Bonjour

I would like to extract the filename and the immediate parent folder  (very usefull to identify a file as index.html in a database when there are more than 200 index.html files)

exemple from a file situated in

table/Documentation/Balisage feux colregs/Texte COLREG RIPAM E-Book/index.html 

I would like to extract only

Texte COLREG RIPAM E-Book/index.html

I find on the forum this answer

${directory;s/.*\/([^\/]*$)/$1/}

BUTR Idon't know how to use it

I try this too

E:\The Yachter - cours au complet\Exiftool>exiftool.exe -csv -r -lang fr -charset latin -ext html -filename -FileTypeExtension -Title -description -author  -FileModifyDate -subject = /(\d{4}-\d{2} [^\/]*)/ ? table > table_recap_html.csv

with that error

Wildcards don't work in the directory specification

Of course I try the solution from Phil Harvey

E:\The Yachter - cours au complet\Exiftool>exiftool.exe -csv -r -lang fr -charset latin -ext html -filename -FileTypeExtension -Title -description -author  -FileModifyDate - subject<Event/${filename;$_ = /(\d{4}-\d{2} [^\/]*)/ ? $1 : undef}  table > table_recap_html.csv

Wich give me this error probably due a bad syntax of $filename

Le chemin d'accès spécifié est introuvable.

Merci


StarGeek

The ${directory;s/.*\/([^\/]*$)/$1/} can be used to copy to another tag but it can't be directly listed with other -TAG options.  You can use the -api Filter option, e.g. -api "filter=s/.*\/([^\/]*$)/$1/", but the has the side effect of affecting all extracted tags.

The other option, and probably the one you'll have to go with, would be to use the -p (-printFormat) option. Something like
exiftool -p "$filename $FileTypeExtension $Title $description $author $FileModifyDate ${directory;s/.*\/([^\/]*$)/$1/}" /path/to/files/
You'll have to adjust it so you get the results in a format that you can use.  You might need to create a FMT file to get things exactly right, which is detailed in the above link.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

ODYSSEUS

Thanks a lot StarGeek

I can use this instructions with no inconvenients in my case

-api "filter=s/.*\/([^\/]*$)/$1/"

but probably I don't use it right because I get no probant results

exiftool.exe -csv -r -lang fr -charset latin -ext html -filename -FileTypeExtension -Title -description -author  -FileModifyDate -api "filter=s/.*\/([^\/]*$)/$1/" table > table_recap_html.csv

Would you like to help me again

ODYSSEUS

#3

Unsuccessfully I try that

exiftool.exe -csv -r -lang fr -charset latin -ext html -filename -FileTypeExtension -Title -description -author  -FileModifyDate -subject ={\/.*\/([^\/]*\/index.html} table > table_recap_html.csv

Or That

exiftool.exe -csv -r -lang fr -charset latin -ext html -api filter="\/.*\/([^\/]*\/index.html" -filename -FileTypeExtension -Title -description -author  -FileModifyDate  table > table_recap_html.csv

StarGeek

Quote from: ODYSSEUS on November 22, 2021, 02:33:16 AM-api "filter=s/.*\/([^\/]*$)/$1/"

but probably I don't use it right because I get no probant results

exiftool.exe -csv -r -lang fr -charset latin -ext html -filename -FileTypeExtension -Title -description -author  -FileModifyDate -api "filter=s/.*\/([^\/]*$)/$1/" table > table_recap_html.csv

You didn't include -Directory in your list of tags to extract.  If you want to list the directory, you have to include it.  Additionally, you can't CD to the directory and run the command because in that case the directory is only a dot .  You must use a path name that's includes at least a couple of levels above the target directory.  If "table" is your directory, then you need to use something like /path/to/table

Example (no Author in the first html file I could find, so no Author column)
exiftool.exe -csv -r -lang fr -charset latin -ext html -Directory -filename -FileTypeExtension -Title -description -author  -FileModifyDate -api "filter=s/.*\/([^\/]*$)/$1/" FoundryVTT\Data\systems\pf2e\templates\actors\crb-style\actor-sheet.html
SourceFile,Directory,FileName,FileTypeExtension,FileModifyDate
/FoundryVTT/Data/systems/pf2e/templates/actors/crb-style/actor-sheet.html,crb-style,actor-sheet.html,txt,2021:07:30 11:52:50-07:00


Quote from: ODYSSEUS on November 22, 2021, 04:45:20 AM
exiftool.exe -csv -r -lang fr -charset latin -ext html -filename -FileTypeExtension -Title -description -author  -FileModifyDate -subject ={\/.*\/([^\/]*\/index.html} table > table_recap_html.csv

It appears that you're trying to extract tags and assign a value  to the Subject tag.  First, you can't do both.  You can either extract tag values or assign values to tags.  Second, exiftool can't edit HTML files, so you can't assign a value to Subject in the first place.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

ODYSSEUS