Applescript how to make file list and move files with certain names - file

I want to make a script that takes a list of names, and moves certain files that have the similar names to the list, into another folder.
To break it down, I have a folder with a few files "appleClient2016.pdf", "fruitClient2016.pdf", "pearClient2016.pdf"
Now I have a list of "appleSept", "pearSept"
I want to move my list into another folder.
I need a script that recognizes appleSept and appleClient2016.rtf both have apple in the string and will move the pdf into another folder. Also it can only move pdf files.
I am very new to applescript but here is my attempt
set listOfFruits to {"appleSept", "pearSept"}
tell application "Finder"
if folder "moveTest1" contains listOfFruits then
move (every file of folder "moveTest1" whose name is listOfFruits) to folder "moveTest2"
end if
end tell
I know I have a few syntax errors here, but I think you get the idea of what im going for.
Any advice would be greatly appreciated.
Thanks!

Think about two things regarding listOfFruits which is a list of strings.
A folder never contains a list of strings it contains a list of files or folders (contains listOfFruits).
A file has never a name which is a list of strings (whose name is listOfFruits).
Basically it is not needed to check 1. with an if clause.
To check if a name is in a list of strings you have to write is in rather than is.
To understand the syntax is in: The expression a is in {a, b, c} is the same as {a, b, c} contains a
set listOfFruits to {"appleSept", "pearSept"}
tell application "Finder"
move (every file of folder "moveTest1" whose name is in listOfFruits) to folder "moveTest2"
end tell

Related

Kettle Get Files Names - listing files from a list of folder names

I am trying to something fairly simple: I have a first "Get File Names" step that generates a list of folder names and a second "Get File Names" step that should take the folder names from the first and list the files in that folder. However, I have trouble getting the second step to work.
Example below
Anyway it is not recursive. It just make what u described. Only files in second level directory.
If u need recursive just use JavaScript Step and Java API to get recursive list of files.

Using a batch file to copy multiple files with the same name, and past into new folder with differing names

I have a long list of files that are auto-produced every month. they'll all have the same file name, with a sequential file extension like this:file.001, file.002, file.003
Each file has differing information, despite having the same name. What I need to do is copy them from their home directory and paste them into a new directory with names that reflect their purpose, and as text files, like this: Budget.txt, Expense.txt, Retention.txt
Is it possible to do this with a batch file? I've been unable to find a method that works. Any help would be appreciated.
EDIT: I've tried that solution, and it works as far as it goes. the frustrating thing is that the extensions are not always the same, but always sequentially numbered.

How to copy the names of the subfolders in a folder, so to use them in a batch program (command line)?

I need to check the files of a versioned system. To do that, I need to write a batcha program so to compare the contents of several folders containing the repositories.
So, my question is: how can I "read" the names of all the subfolders inside a folder, so to use these names later to find subfolders having the same names in a different repositories?
I suppose I may use DIR to print on the screen a list of these names but I don't know how to write it on a text file and then read it. Moreover, I should edit this kind of list, anyway.
Any suggestions or new ideas to solve this problem?
I thank gratefully who ever will answer.
it seems that you can get the subfolders using batch file from perl as follows:
system("start C:\\Temp\\mybatchfile.bat");
or you might try to pass your command suggested by #Stephan straight to system and try to handle what it is returned.

How to move subdirectories including files from directory

On a shared drive there is a directory "Q:\batch_Rxaoutput" inside that directory there are over a thousand directories for example "Q:\batch_Rxaoutput\SUNY" or "Q:\batch_Rxaoutput\PDFL". The subdirectory within "Q:\batch_Rxaoutput" contains only four letter codes where monthly reports are outputted by an SSIS package. Sometimes a report needs to re-ran due to errors so there are multiple reports created within one of the thousand or so output locations. My goal is to loop through each folder insided "Q:\batch_Rxaoutput" and move the folders, subfolders and files contain the same name.
For example in Q:\Batch_Rxaoutput\EEKY there is:
Q:\Batch_Rxaoutput\EEKY\Dec2014_20150108044150
Q:\Batch_Rxaoutput\EEKY\Dec2014_20150114090454
Q:\Batch_Rxaoutput\EEKY\Dec2014_20150115094531
Q:\Batch_Rxaoutput\EEKY\Feb2015_20150302122307
Q:\Batch_Rxaoutput\EEKY\Jan2015_20150202214348
Q:\Batch_Rxaoutput\EEKY\Jan2015_20150214223734
I want to to move only the no current folders,subfolders and files.
the monthly folder names are Month.year_year.month.hours(military).hours.seconds.milliseconds
So basically if there are multiple folder names Feb2015_* or Jan2015* move the ones that have the lowest numeric value after the underscore.
I would love to accomplish this from a .bat cmd if possible.
Please let me know if there is more info that would help!

How to copy a freshly created array containing files to another folder on the same computer

I am new to Powershell but have had experience with various programming languages including dBase III, basic, Fortran (shows my age). I am a musician and launch MP3 files as an accompanyment when I perform live, somewhat like karaoke. I have about 45 different MP3s that I use. I like to change the sequence of the songs that I perform, from time to time and this requires renaming the MP3 file names with a preceeding sequence number. The file names take on the form: "01 songnameA.mp3", "02 songnameB.mp3", "03 songnameC.mp3", etc. I also repeat songs so there might be an "09 songnameA.mp3" in the folder that I play back from. To do this, I typically create a text file that lists the songs in the order that I want to perform them. Each line in the text file has the form "01 Songname X" but no MP3 extension. I then manually copy the mp3 files into a folder and then edit the names applying a sequence number according to the text file. This is time-consuming.
I have created a Powershell script (version 2) that creates an array of the text file content and an array of the unnumbered MP3 song files. The script creates a 3rd array containing numbered MP3 filenames according to the sequence in the text file. This array does work and I can easily display the list of items in it which have the form "01 SongnameX.mp3". However, I have been unable to copy this array of MP3 filenames with a preceeding sequence number into another folder. I don't know how many variations of the "Copy-Item" statements I have tried but nothing works. The name of the array that contains the filenames is $nsfarray (new song file array). The command I am presently using:
$nsfarray | copy-item -Destination C:\temp
Returns the following error message:
Copy-item : Cannot find path 'C:\Users\My HP\Documents\My Scripts\01 A Good Time.mp3' because it does not exist.
The path is the default path that I use to run Powershell but somehow the MP3 file names get appended to it. The "01 A Good Time.mp3" is the first item in the $nsfarray. I know I am missing something here. Any suggestions would be appreciated.
This is really crude but the issue I see with your input file is that it obviously does not exactly match the real file name that you are looking to copy. So with that in mind lets try this on for size.
$musicPath = "c:\music"
$destinationPath = "c:\songset"
$nsfarray = "01 Age of Aquarius"
$nsfarray | ForEach-Object{
If($_ -match '^\d+ *(?<BaseName>.*)'){
Copy-Item "$musicPath\$($Matches.BaseName).mp3" -Destination "$_.mp3"
}
}
Work with explicit paths: $musicPath and $destinationPath so that we do not have to rely on our current location in PowerShell. Then we navigate each value in the array, which I have populated with one example. Now we need to extract the real file name away from your set list number. Using regex we return the part of the string that is not the beginning numbers and spaces and take everything after that.
After we simply copy the file that exists in the $musicPath folder that has the name "Age of Aquarius.mp3", which should be the real file, and copy it to the $destinationPath as "01 Age of Aquarius.mp3", which is how you want the file for your gig.
Clarification
After answering this and looking back at the question I think there is a chance I didn't understand it right. Please update the question if this is not the right way to address this. The core of your problem, if nothing else, is that you are not specifying a proper file path for the mp3s. You need to use the proper source folder and append the mp3 to the string.

Resources