Powershell Only:File name change according to mapping file and then copy to another directory - powershell

I have a mapping file in import.CSV as following:
Name|Business
Jack|Carpenter
Rose|Secretary
William|Clerk
Now, I have a directory which contains files like
90986883#Jack#Sal#1000.dat
76889992#Rose#Sal#2900.dat
67899279#William#Sal#1900.dat
12793298#Harry#Sal#2500.dat
Please note #Sal will always be there after Name. I need to pick these files and put into another directory and end result in second directory should look like.
90986883#Carpenter#Sal#1000.dat
76889992#Secretary#Sal#2900.dat
67899279#Clerk#Sal#1900.dat
Basically Files need to be renamed based upon CSV file and if Name is not there in file name , then there is no action required. Please note that source file should not be changed.
I will appreciate all kind of help.

Related

How to rename an XML file using the pattern in a different .txt file?

I have a folder say, source folder, containing 1000+ xml files with some ambiguous names, like:
_MIM_15646432635_6664684
_MIM_54154548557_6568436 etc.
Out of these thousands of XML files I’ve to select some 10-12 xml files with a particular node in them and move them to another folder (destination folder) and rename the files respectively with some meaningful names.
For example:
There is an xml file with name _MIM_15646432635_6664684 and it contains a node pattern like: “bab6e7h835468eg” and I’ve to rename it to name like: {1FE9909E-4450-B98665362022}
So for this I’ve to write a script which will search the file in source folder and if it finds my desired node pattern then move this file to destination folder post renaming it to some meaningful name.
Provided I’ve an excel sheet where I do have a list of two columns, one containing the specific node pattern and column two has a respective new name list.
Currenty, I’ve a script which can search a file and move it to another folder provided I’m giving input to the script with the node pattern and file name from that excel sheet:
Select-String – Path “\Dubwta01\AIR\Invalid*.xml” – Pattern ‘bab6e7h835468eg’ | %{Copy-Item – Path $_.Path – Destination ‘\Dubwta01\AIR\Invalid{1FE9909E-4450-B98665362022}.xml’
What now I need is that a new script which will pick all 10 files from source folder and move it to destination folder by renaming it and I don’t have to hard code the pattern and new name in script rather it shall fetch the details from that excel or I can save the details in text files whatever is suitable for script to pick the name and pattern from.

How to move files whose file name is not used in a set of text files?

I'm a Powershell beginner and this is my first post on stackoverflow. I can understand some simple pipelines, but the following challenge is too complicated for me at this point:
I have a folder with testdata containing *.bmp files and their associated files. I want a powershell script to check which bmp-files are still used. If not used, move bmp-files and associated files to another folder.
Details:
bmp-files and associated files: For example; car01.bmp, car01.log, car01.file, car02.bmp, (...)
The bmp-files are in use if their file name (eg, car01.bmp) is mentioned in any of the (text/csv) files in at least one of 2 locations (incl. subfolders).
If the file name is not found in any of the text files, I want the script to move that file, and any file who's name differs only by file extension to a designated folder.
Looking forward to your solutions!

Rename pentaho multiple .ktr files in my folder

I have multiple .ktr transformation files in one of my folder. I've used spaces in the naming convention. So, I want to rename all those pentaho transformation files using "Spoon". Are there any steps that can rename all my files at once?
Example : I've file calles "Invoice Items.ktr".
I want to rename this file to "InvoiceItems.ktr".
There isn't a step that does "Rename" action, you need to generate a new filename and move the file to itself.
You can use this with a series of steps for this.
EDIT:
In the get file names step, in the Wildcard column, use RegEx ".*", this will select all files within that folder. In the File/Directory column you leave only the directory, not the full filename.

MatLab - accessing subfolders of folders saved as variables

I have the following code which can create a directory within a selected folder:
photos_dir = 'C:\Users\Bob\Photos';
mkdir(photos_dir,'Christmas 2015')
I'd like to then be able to save an image to this folder, I think using something like:
imwrite(img,Christmas 2015,'jpg')
However, this does not select the "Christmas 2015" folder which is in the "\Photos" directory. How can I make the image be written to this location?
First of all, you're going to have a syntax error since Christmas 2015 should at least be a string. But other than that, if you want to save a file in a particular location (other than the current working directory), you need to provide the full path to the file location.
To do this, you need to use fullfile to combine all of your directory and file names together into a full file path.
image_name = fullfile(photos_dir, 'Christmas 2015', 'yourphoto.jpg');
imwrite(img, image_name, 'jpg')

Copy permissions form source file to file with same name

I 've got over 1000+ .xls files with names like "65223p.xlsx" and I need to copy permissons from this files to files with same name , but without "p".
Each file have different permissions than another.
Can you help me? Thanks.