Rename a group of .txt files based on content that appears after a specific string in the text file? - powershell

I have a folder with hundreds of text files in it. The file names have zero meaning. I am trying to extract a variable number that appears after a string in each file and and rename the files using it. I'm somewhat of a Powershell newbie (an old timer form the DOS world) but I have written many useful scripts with it. I've searched high an low, this one has me stumped.
Any and all suggestions are welcome, or I'd happily pay someone for the snippet of code. -Ed

Related

Powershell search for pattern with itextsharp.dll

I need to search pdf-files for patterns and then I just want the name of the files containing "region värmland", using that to copy the files to a different folder.
The pattern is in the top right corner, and if possible I would like to search as little as possible in the file due the number of files.
I could not find any relevant information when googleing how to just search for one set of words and keep the output inside the script for further use.
Anyone who can help with this?

Tool/Script to Automate File Naming From Metadata

I have a folder containing 1000+ PDF files with generic names (i.e. DOC (1)) that I need to rename with the order number, which is listed inside the file itself. I've had to manually open each document, look for the order number, then change the file name.
I have a spreadsheet list of all of the order numbers contained in that folder. I've used the search function of the file explorer to look up each individual order #, then renaming whichever file comes up. This has reduced the task time substantially but it's still very time-consuming.
Does anyone know of a macro or scrip that I can build to automate the task? Again, I would need something to grab the order number line by line from the spreadsheet, then go to the file explorer to search for any files with that specific term, and finally rename whichever file comes up with said term.
Any and all relevant help is greatly appreciated.
Thank you in advance for your time!

Extracting file names from an online data server in Matlab

I am trying to write a script that will allow me to download numerous (1000s) of data files from a data server (e.g, http://hydro1.sci.gsfc.nasa.gov/thredds/catalog/GLDAS_NOAH10SUBP_3H/2011/345/). Unfortunately, the names of the files in each directory are not formatted in a similar way (the time that they were created were appended to the end of the file name). I need to be able to specify the file name to subset the data (I have a special tool for these data types) and download it. I cannot find a function in matlab that will extract the file names.
I have looked at URLREAD, but it downloads everything including html code.
Thanks for your help!
You can easily parse the link.
x=urlread(url)
links=regexp(x,'<a href=''([^>]+)''>','tokens')
Reads every link, you have to filter all unwanted links.
For example this gets all grb files:
a=regexp(x,'<a href=''([^>]+.grb)''>','tokens')

how to annotate files - when long filenames are not enough

I work with many files doing general data analysis.
Things I want to know about my files include:
what data is contained in the file (in long and very long descriptive, english text)?
is the file downloaded from somewhere (where? when?) or generated by a program (which one?)
why I made this file, verbal description what I want to do with it, where it belongs in my data analysis workflow (additional english text description, can get very long as well)
For this, long filenames are simply not the solution! Even long filenames are too short for the full descriptions, and when actually working with the files (perl, awk, R) the long filenames get in the way.
What I do right now is make a readme in each dir with the filename, tab-separator, and the long description. However this solution is very cumbersome as you can imagine because the descriptions are completely separated from the filesystem and everything, the readme has to be maintained and updated separatedly etc.
Is there any tool one can use for really verbose, systematic descriptions of filenames? Maybe even integrated into the filesystem?
Operating system used: Windows 7 and Cygwin, various flavours of linux/unix through SSH and importing X

smlnj rephrased question for listdir(filename, directoryname)

i am a newbie learning sml and the question i am thrown with involves IO functions that i have no idea how it works even after reading it. Here is the 2 questions that i really need help with to get me started, please provide me with codings and some explaination, i will be able to trial and error with the code given for the other questions.
Q1) listdir(filename,directoryname), which given the name of a directory, list its contents in a text file. The listing is in a form that makes it easy to seperate filenames, dates and sizes from each other. (similar to what msdos does with "dir" but instead of just listing it out, it places all the files and details into a text file.
Q2) readlist(filename) which reads a list of filenames (each of which were produced by listdir in (Q1) and combines them into one large list. (reads from the text file in Q1 and then assigning the contents into 1 big list containing all the information)
Thing is, i only learned from the lecturer in school on the introduction section, there isnt even a system input or output example shown, not even the "use file" function is taught. if anyone that knows sml sees this, please help. Thanks to anyone who took the effort helping me.
Thanks for the reply, current I am using SMLNJ to try and do this. Basically, Q1 requires me to list the directory's files of the "directoryname" provided into a text file in "filename". The Q2 requires me to read from the "filename" text file and then place the contents into one large list.
Duplicate of: smlnj listdir
As a hint I will say that you have to make use of these functions:
OS.FileSys.OpenDir(directoryname) - this will open directory stream for you (Q1)
TextIO.openOut(filename) - this will open the file stream (Q2)
TextIO.openIn(filename)- this will open the file (Q2)
If you are stuck and dont' know how to do the progs then I will post the full code here, but i suggest you first give a try.
zubair sheikh