I have a piece of script that takes the file name from each file in a given folder and then creates a CSV file with the list of file names. I need to modify this script to only extract the numbers from the file name and not the text.
current file name convention in folder : sz_123456_a
(the text is not always the same)
extract only : 123456 and create a csv file list.
here is the script I am using at the moment is there a way I can modify this to just extract the numbers?
I thought Nigel’s clever sed regexp deserved something faster than the Find command. This won’t work properly, if your Spotlight database is broken, though you’ll quickly see that the database is broken by spotting (pun intended) the gear icon when searching for say an app, on the Spotlight menu.)
do shell script "mdfind -onlyin ~//Desktop/images 'kMDItemFSName = \"*pdf\" ||kMDItemFSName = \"*jpg\" ' | sed -E 's|.+/([^/]+)$|\\1| ; s|[^0-9]+|\"|g'> $HOME/Desktop/file_names_list.csv"
Well, there are some troubles with doing just that; the problem is that if the file is either downloaded, or created elsewhere on your disk, then attributes like creation date, modification date,and access date, are already set.
When we peruse through the folders, then we stat the file, so if I’m not totally wrong, then the access attribute of the file will be updated.
The short story is, that in order for you to know when the file entered the folder, then you’d either have to create the file in the folder system, or you’d have a special way of copying the file, which for instance updated the creation time/date to the point in time where you copied the file into the filesystem for your images.
I suggest you’d use the modification time / date to set when it was added to the folder, thereafter, you’d take the stance that each time you have modified a file, it is added to the folder, which will be after the time you physically added it to the folder anyway.
I wonder if you have any thoughts about this, so far.
The accestime (atime) of a file only changes when the contents of a file is read.
The change time (ctime) of a file only changes when either the contents is changed, or the attributes of the file is changed.
The modification time (mtime) of a file only changes when the contents of a file is modified.
Nothing of this changes my proposal of changing the modification time of the file, when it was added to the folder hiearchy really, and then later on using that modification time to symbolize when it was added to the folder, also when the contents of the file has been indeed modified.
I didn’t notice that you had written back on this thread before now. Hopefully, you have learned to use the modification date instead of the creation date.
Because the creation date, is rather hard to use I figured. Actually, the creation date isn’t part of the unix file system, but is something special for OS X. The trouble is, is that I have to dig it out of the Spotlight metadata, and when I get it from there, then it may be ‘encoded’: that is, if the file is from an external source,then the there is no creation date, at least not until you modify it. This means that I not only have to filter the output, but I also have to read the contents of it, and I am not sure if I have the correct ‘not created here’ timestamp for an imported file either. ->seems like: it is ‘4001-01-01 00:00:00 +0000’ on my system. ( I used the command
It is not only cumbersome, but it will also be a bit slower.
Anyways, I’d like to hear from you before I start writing it.