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

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!

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.

What is the usage of blacklist.txt in pythonforandroid (p4a)?

In the documentation of pythonforandroid, at https://python-for-android.readthedocs.io/en/latest/buildoptions/, there is a build option described called blacklist.
--blacklist: The path to a file containing blacklisted patterns that will be excluded from the final APK. Defaults to ./blacklist.txt
However, not a word can be found anywhere about how to use this file and what exactly the patterns are supposed to represent. For instance, is this used to exclude libraries, files, or directories? Do the patterns match file names or contents? What is the syntax of the patterns, or an example of a valid blacklist.txt file?
This file should contain a list of glob patterns, i.e. as implemented by fnmatch, one per line. These patterns are compared against the full filepath of each file in your source dir, probably using a global filepath but I'm not certain about that (it might be relative to the source dir).
For instance, the file could contain the following lines:
*.txt
*/test.jpg
This would prevent all files ending with .txt from being included in the apk, and all files named test.jpg in any subfolder.
If using buildozer, the android.blacklist_src buildozer.spec option can be used to point to your choice of blacklist file.

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

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.

dspace command line import files not appearing in collection

I am running dspace 6.1 on Suse 12.2. I have used the command line import command to bring files into a collection, and the command prints out that it succeeded.
bin/dspace import --add --eperson=myemail#mycompany.com --
collection=123456789/49 --source=/opt/dspace/import_dateien/test/ --
mapfile=mapfile
Destination collections:
Owning Collection: 1982-11-10 Collection
Adding items from directory: /opt/dspace/import_dateien/test/
Generating mapfile: mapfile
Started: 1503332092481
Ended: 1503332095888
Elapsed time: 3 secs (3407 msecs)
I have added files without additional metadata, and no SAF zip file, because I want the extra files in the collection without their own metadata, only the existing set of metadata.
The name of the collection is correct in the success message. But I do not see the files in the collection. Are they there, but hidden? How can I get them to appear?
It appears that the command found zero items in the batch. You should see several lines of output for each item.
The first thing I would check is that the source directory "/opt/dspace/import_dateien/test/" conforms to SAF: it should contain numbered subdirectories, each containing one item. The importer seems to find no directories there.
I found it! I was using SAFBuilder, and there one has a csv file, with one line per file, each file with metadata. But, the SAFBuilder script creates a folder as well as a zip file, and in this folder are the files, a text file named contents, and the metadata as xml. One can simply add here the extra files one wants to add, list them in the contents file, and re-zip it. I just tested it with bin/dspace import, and there are my extra files in the collection. As #Mark Wood said, my files were listed in the output from the script.

Renaming files in Matlab - movefile is creating folders instead of files

The current working directory contains a folder called 'dynamics_sorted' which contains 300 subfolders ('001', '002', etc), each of which contains some files, but only a single nifti (.nii) file.
The single nifti file from each of the numbered subfolders should be moved into 'dynamics_sorted_NIFTI' which is in the current working directory.
In the process, each nifti file should be renamed with the number of its parent folder.
The syntax for movefile suggests that when the arguments are both filenames then the file is renamed
http://uk.mathworks.com/help/matlab/ref/movefile.html#zmw57dd0e528520
for Ticker = 1:300;
FindNiftiFile = ['dynamics_sorted/',num2str(Ticker,'%03.0f'),'/*.nii'];
PutNiftiFile = ['dynamics_sorted_NIFTI/',num2str(Ticker,'%03.0f'),'.nii'];
movefile(FindNiftiFile,PutNiftiFile);
end
But this code does not rename the files, instead it keeps the filenames but places them into numbered folders.
Any advice as to where the error is?
I've found the answer - it's because of the wildcard used to find the source file. I'm guessing this leads Matlab to assume the source is not a single file, even when the wildcard is such that only a single file is eligible.