A script for copying certain files to a new location
I have a folder with over 50,000 images in it. I need about 15,000 of them copied to another folder.
Is there a script (that I can paste the list of the ones I need copied) to perform this action?
Thanks in advance.
perhof,
After much googling, I was fortunate enough to find your beautiful script!
I added a couple of things like subfolder recusion ( by tweaking scripts I found) .
Would you be kind enough to look this over and see if it's ok or needs fixing?
Thanks for any help,
ec
[code]
' Read a list of images from text file
' and copy those images from SourceFolder\SubFolders to TargetFolder
' Should files be overwriten if they already exist? TRUE or FALSE.
Const blnOverwrite = TRUE
Dim objFSO, objShell, WSHshell, objFolder, objFolderItem, strExt, strSubFolder
Dim objFileList, strFileToCopy, strSourceFilePath, strTargetFilePath
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
Set WSHshell = CreateObject("WScript.Shell")
Const ForReading = 1
' Make the script useable on anyone's desktop without typing in the path
DeskTop = WSHShell.SpecialFolders("Desktop")
strFileList = DeskTop & "\" & "images.txt"
' File Extension type
strExt = InputBox("Please enter the File type" _
& vbcrlf & "For Example: jpg or tif")
If strExt="" Then
WScript.Echo "Invalid Input, Script Canceled"
Wscript.Quit
End if
' Get the source path for the copy operation.
Dim strSourceFolder
Set objFolder = objShell.BrowseForFolder(0, "Select source folder", 0 )
If objFolder Is Nothing Then Wscript.Quit
Set objFolderItem = objFolder.Self
strSourceFolder = objFolderItem.Path
' Get the target path for the copy operation.
Dim strTargetFolder
Set objFolder = objShell.BrowseForFolder(0, "Select target folder", 0 )
If objFolder Is Nothing Then Wscript.Quit
Set objFolderItem = objFolder.Self
strTargetFolder = objFolderItem.Path
Set objFileList = objFSO.OpenTextFile(strFileList, ForReading, False)
On Error Resume Next
Do Until objFileList.AtEndOfStream
' Read next line from file list and build filepaths
strFileToCopy = objFileList.Readline & "." & strExt
' Check for files in SubFolders
For Each strSubFolder in EnumFolder(strSourceFolder)
For Each strFileToCopy in oFSO.GetFolder(strSubFolder).Files
strSourceFilePath = objFSO.BuildPath(strSubFolder, strFileToCopy)
strTargetFilePath = objFSO.BuildPath(strTargetFolder, strFileToCopy)
' Copy file to specified target folder.
Err.Clear
objFSO.CopyFile strSourceFilePath, strTargetFilePath, blnOverwrite
If Err.Number = 0 Then
' File copied successfully
iSuccess = iSuccess + 1
If Instr(1, Wscript.Fullname, "cscript.exe", 1) > 0 Then
' Running cscript, output text to screen
Wscript.Echo strFileToCopy & " copied successfully"
End If
Else
' Error copying file
iFailure = iFailure + 1
TextOut "Error " & Err.Number & _
" (" & Err.Description & ")trying to copy " & strFileToCopy
End If
Next
Next
Loop
strResults = strResults + 0 '& vbCrLf
strResults = strResults & iSuccess & " files copied successfully." & vbCrLf
strResults = strResults & iFailure & " files generated errors" & vbCrLf
Wscript.Echo strResults
Sub TextOut(strText)
If Instr(1, Wscript.Fullname, "cscript.exe", 1) > 0 Then
' Running cscript, use direct output
Wscript.Echo strText
Else
strResults = strResults & strText & vbCrLf
End If
End Sub
Function EnumFolder(ByRef vFolder)
Dim oFSO, oFolder, sFldr, oFldr
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Not IsArray(vFolder) Then
If Not oFSO.FolderExists(vFolder) Then Exit Function
sFldr = vFolder
ReDim vFolder(0)
vFolder(0) = oFSO.GetFolder(sFldr).Path
Else sFldr = vFolder(UBound(vFolder))
End If
Set oFolder = oFSO.GetFolder(sFldr)
For Each oFldr in oFolder.Subfolders
ReDim Preserve vFolder(UBound(vFolder) + 1)
vFolder(UBound(vFolder)) = oFldr.Path
EnumFolder vFolder
Next
EnumFolder = vFolder
End Function
[/code]
Similar Messages
-
A script for copying smilar files to a new location
Hi,
i newbies to scripting. My challenge is that I want a script to only copy files with names "similar" and not "exactly the same" as the filenames in the text file.
For example some files have 10 letters file name like "ABC01FGH01.tif". I have to copy file where starting letter "ABC" and middle letter "FGH" of file name are fixed, but other letters are changed.
The script sees a file name like "ABC**FGH**.tif", it should search the source location and copy the files having filenames with at least this characters e.g. "ABC02FGH02.tif", "ABC03FGH04.tif" should be copied since it has
contains "ABC**FGH**.tif".
Please help.Learn how to use wildcards in file names. '*' is for any number of characters and'?' is for one character.
COPY ABC??DE???.?x? c:\target
Start by using DIR
DIR ABC??DEF???JK.?x?
¯\_(ツ)_/¯ -
AppleScript: copy a file to a new location, changing its name
I want to copy a selected file to a new location and change its name, both location and name adjustable by the user. It would seem natural to me (a neophyte) to use the Duplicate and Choose File Name commands to do this, so this is the module I came up with:
tell application "Finder"
set myFile to the selection
set textsAlias to alias "Campidoglio:Users:jeffreyjdean:Dropbox:Tinctoris:Editing Software:TextToJS:texts:"
set fileForConversion to choose file name default name "shortname.txt" default location textsAlias
try
duplicate document file myFile to fileForConversion with replacing
on error
display dialog "Error: Unable to save file."
end try
end tell
This doesn't work. The error dialog comes up and this is the result report:
tell application "Finder"
get selection
--> {document file "12 De inventione et usu musice.txt" of folder "Edited texts" of folder "Desktop" of folder "jeffreyjdean" of folder "Users" of startup disk}
choose file name default name "shortname.txt" default location alias "Campidoglio:Users:jeffreyjdean:Dropbox:Tinctoris:Editing Software:TextToJS:texts:"
--> file "Campidoglio:Users:jeffreyjdean:Dropbox:Tinctoris:Editing Software:TextToJS:texts:shortname.txt"
-- 'core'\'clon'{ 'insh':'furl'("file://localhost/Users/jeffreyjdean/Dropbox/Tinctoris/Editing%20 Software/TextToJS/texts/shortname.txt"), 'alrp':'true'("true"), '----':'obj '{ 'form':'indx', 'want':'docf', 'seld':[ 'obj '{ 'form':'name', 'want':'docf', 'seld':'utxt'("12 De inventione et usu musice.txt"), 'from':'obj '{ 'form':'name', 'want':'cfol', 'seld':'utxt'("Edited texts"), 'from':'obj '{ 'form':'name', 'want':'cfol', 'seld':'utxt'("Desktop"), 'from':'obj '{ 'form':'name', 'want':'cfol', 's…
--> error number -1700 from {document file "12 De inventione et usu musice.txt" of folder "Edited texts" of folder "Desktop" of folder "jeffreyjdean" of folder "Users" of startup disk} to integer
display dialog "Error: Unable to save file."
--> {button returned:"OK"}
end tell
Result:
{button returned:"OK"}
Why is it telling me it can't duplicate a file to an integer? According to the AS Language Guide, the result of Choose File Name is "The selected location, as a file." How does this become an integer in my script?
That may be a side show. What I really want to work out is how to achieve the aim stated at the beginning: take a selected file (that part is working OK) and duplicate it to an arbitrary location with an arbitrary new name, decided by the user. What's the best way to go about this?
TIA,
Jeff
Message was edited by: Jeffrey DeanI think you're misinterpreting the error message.
It's not complaining about your 'Choose File Name', per se.
There are two problems with your script.
First, you:
set myFile to the selection
As far as the Finder is concerned, 'selection' is a list. It's always a list, even if only one item is selected - heck, it's still a list if no files are selected... just an empty list.
So that's the first thing the script is complaining about - you are using a list that you're trying to coerce to a file. Can't happen.
You have a couple of options here, depending on what you want to do.
You can tell the Finder to duplicate a list - it will simply duplicate all the files in the list. It has no problem with that, although you're going to run into problems when you try to set the file name(s). This highlights one of the design flaws with your script - how do you know the user only has one thing selected? At the very least you should check how many items are selected and react accordingly.
The other option is to iterate through the list, duplicating each file in turn. Again, it's not clear what you want/expect the outcome to be here - since you include 'with replacing', you'd likely end up with one file (the last one in the list) as being the named file and all other duplicates lost.
The third option is to expect there to be one item selected, and just act upon the first one - thereby ignoring multiple selections, although it's undefined as to which item is 'first' in the list.
Your call.
Once you get over the issue of identifying what you want to duplicate, the second issue with your script is how you're calling duplicate. You cannot duplicate one file to another file name. The duplicate command expects (demands?) a directory as the 'to' parameter, not a file name.
In other words, you can duplicate a file to a new directory. You cannot duplicate it to a new file name - at least not in one step. In order to do that you need to duplicate the file, then change its name (or use a shell script to do it 'under the hood').
This is complicated by the fact that it's the rename that requires you to check for duplicates, which you have to do manually.
So given the above, and assuming you expect/want one item to be selected, your script should look more like:
tell application "Finder"
set myFile to item 1 of (get selection) -- ignore multiple selections
set textsAlias to alias "Campidoglio:Users:jeffreyjdean:Dropbox:Tinctoris:Editing Software:TextToJS:texts:"
set fileForConversion to choose file name default name "shortname.txt" default location textsAlias
set fDir to do shell script "/usr/bin/dirname " & POSIX path of fileForConversion
set fName to do shell script "/usr/bin/basename " & POSIX path of fileForConversion
try
set newFile to duplicate myFile to POSIX file fDir with replacing
if (exists file fName of folder fDir) then
delete file fName of folder fDir
end if
set name of newFile to fName
on error
display dialog "Error: Unable to save file."
end try
end tell
Incidentally, this is something that could be much more easily done with a shell command, since the shell isn't as sensitive about file paths and data types. -
Wait for download to complete, then copy the file to a new location
I am downloading some files with PowerShell using webclient.downloadfileasync.
Im using "Start-sleep -s 10" to prevent the files to be copied before it is completed, but sometimes the download takes longer than 10 Seconds or the url is not accessible. Is there some way to check when the file is completed?
Or maybe another solution is to check the url before it even starts downloading.
try
foreach ($urls in $ip)
$url = $http + $ip
$path = $local + $nr + $jpg
$client = New-Object System.Net.WebClient
$client.DownloadFileAsync($url, $path)
finally
$client.dispose()
Start-sleep -s 10
Copy-Item C:\data\*.jpg C:\data\images
$cn.Close()Hi,
Try using the DownloadFile method instead of DownloadFileAsync:
http://msdn.microsoft.com/en-us/library/ms144194%28v=vs.110%29.aspx
Don't retire TechNet! -
(Don't give up yet - 12,830+ strong and growing) -
MAXL Script for copying outline
Can we write any MAXL Script for copying outline from one aplication/datbase to another application/database.
Example copying olt from app1.dbb1 to app2.dbb2No and yes.
There is no MaxL statement for copying an outline from one DB to another (Unless you are converting from BSO to ASO). But you can shell system commands like xcopy within a MaxL script (of course you could just do this in your batch or shell script) . Just make sure you stop the Dbs before doing the copy -
Need Shell Script for picking the files
Hi,
I want to write a shell script for piking the files in a sequence order (according to filename with time stamp) from the sorce FTP server ..
Requirement is in the source directory I'm getting files (Jain_1.xml , Jjain_2.xml, Jain_3.xml .. ect..) at present my file adapter is picking all the files at a time but i want to pick one by one... that to first i want to Jain_1.xml after finish the processing of the file then only my file adapter should pick the next file ( Jain_2.xml ) .
so.. all the forum mates suggest me to write a shell script.. but where i have to write the s hell script. and where i have to deploy this script.... my Xi is running on UNIX ... so please sugest me the procedure ...
Regards
JainHi,
Why dont you use the option EOIO in which files will be picked up in order and will be proccessed in sequence....one after another....
Regards,
Sreeni. -
From Forms 5.0 I want to copy a file/folder from one location to another.
Hi,
I have a question and I really appreciate your help.
My Question is
I would like to copy a file/folder from one location to another.
(For ex: From my Hard disk to a Network folder).
I want to do this from Oracle Forms 5.0 and my operating system is Windows 2000/NT Workstation.
At present my users are doing this by using drag and drop windows functionality,
But now they want to do this by using a GUI screen.
I would greatly appreciate if somebody can answer my question.
Thank you very much and have a nice day.
Thanks & Regards
Sanjeev.Hi Shay,
Am able to copy the files/folders by doing the follwing.
Declare
My_Command Varchar2(1000);
Begin
MY_COMMAND := 'XCOPY /E ' ||:FROM_LOC ||' '|| :TO_LOC ;
HOST(MY_COMMAND);
End;
But my problem is am not able to trap the errors.
Do you have any idea?
Thanks -
I can't import photos from a card, file or anything. I get "could not copy a file to the requested location". I have never had this happen before. I use a MacBook Pro
I also have the exact same issue. New IMac, installed LR, imported approximately 900 photos no problem, across the network from a Windows PC. The import stopped when the network connection was lost. Now I cannot import for the same reason "could not copy a file to the requested location". I have plenty of disk space and i have permission to the needed folders. I cannot even import from a folder already on the IMac.
-
"Could not copy a file to the requested location." error
Hi - I'm running Adobe Lightroom 1.4.1 (latest) on my iMac which is running Leopard's latest version. Suddenly I'm getting an error when importing to Lightroom. I have used different CF cards, so I'm sure it's Lightroom. Either one or two photos import (out of a large amount - this happens whether in RAW or JPG) and then it quits with a pop-up, which at the very top says "Import Results", and under there it says, "Some import operations were not performed." In the space below there's a header that says, "Could not copy a file to the requested location. (92)" (Not always 92, sometimes 200 or something else), and there is a triangle to expand and all the photo file names are listed below.
Everything was running fine until yesterday, nothing changed. I have screen shots of the error if needed. Help??? Please! I have so many photos to import!
Thanks for any help,
AvivaSame problem here only with images burned to disks today, it is fine with images burned to disks 3 days ago. This is happening on two computers one is running XP with Lightroom 1.4 the other is running Vista with Lightroom 1.3. I can import one image at a time but no batches off DVD or CD disks, I have not tried directly from my CF cards. We have found a work around; download all images to temp folder on desktop then import into Lightroom after imported delete files in temp folder it works but takes a lot more time and space on hard drive.
-
when using migration does it copy the files to the new computer or transfer them (leaving the files only on the new computer)?
It leaves them on the old computer. Nothing will be changed on it.
-
In PC I have changed the default app location from (c:/users/username/My Music/iTunes) to other (d:iTunes) and copied the previous content to new location and changed the Default location in Edit preference. Now in iTunes, my previous apps are not visible. Is there any solution to this?
wjosten - thanks very much for the detailed instructions. I'll try this as soon as I get my replacement and it looks like you'll probably end up getting the green tick
-
In pages,how do I copy an image to a new location by click & drag?
in pages,how do I copy an image to a new location by click & drag?
To MOVE an image to a new location, Click and Drag the image.
To move a COPY of the image to a new location, leaving the original in place, pres and hold the Option key as you Click and Drag the image.
Regards,
Barry -
Logon Scripts for copying files in Windows 7
Issues using Logon scripts to copy files in windows 7. Its default is to append the file rather than copy and replace, which is what XP did. How can I achieve the same results using
logon scripts in W7 to copy any files to specified folders and replacing old files. The reason for this is that we use a software that performs offsite/onsite updates and the only way all the users can have the correct version/tables is to either manually
update each user in a 90+ user environment or use a logon script to perform the coping of the updates. Unfortunately the software support won’t create a (while logging in to software) patch for this. So we have to force it during the user logon.Hi Novice,
It should depend on your script content. it's recommended you ask in the official scripting guys forum for professional help:
https://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=ITCG
Karen Hu
TechNet Community Support -
Script for copying or moving files from windows server to another remote windows server
Copy below 2 line into notepad and save as movescript.vbs
execute in command prompt
c:\cscript movescript.vbs (Press ENTER)
Files will move to remote location.
=========================================
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "C:\scripts\*.txt","\\servername\c$\share"
=========================================
for copy files to remote location
=========================================
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "C:\scripts\*.txt","\\servername\c$\share"
=========================================
Lets us know if you face any error. reply back to me on [email protected]
Thank you.....
Regards Ravikiran MCITPWhat is your question? Are you asking how to do this? Can you post the errors?
¯\_(ツ)_/¯ -
Script to Copy preference file to all users profiles and to the default template
I have build a package using Apple PackageMaker, this will install an application and a preference (plist) file to the current logged in user. Now I wanted to build a postflight script, which can copy a plist (ex com.test.plist) form an current logged in user to other user account on a machine also to the default user template (/System/Library/user template/...../Library/preferences) so any new user account created will have same preference file copied.
Hi Mark...here is another script which work well if I have to copy my preference file from an account named as "admin" or some other account. However, it not certain that all Mac machine will have a account named as "admin". This is why I am looking for a way to copy the preference file from /private/var location to all user accounts on a mac.
#!/bin/sh
localUsers=$( dscl . list /Users UniqueID | awk '$2 >= 501 {print $1}' | grep -v admin )
for userName in "$localUsers"; do
cp /Users/admin/Library/Preferences/org.mypreference.plist /Users/$userName/Library/Preferences/
chown $userName /Users/$userName/Library/Preferences/org.mypreference.plist
done
I tried to update it as suggest in some other forum like this, still no luck
#!/bin/sh
UserAccounts=`dscl . list /Users UniqueID | awk '$2 > 500 { print $1 }'`
for userName in "$UserAccounts"; do
cp /private/var/org.mypreference.plist /Users/$userName/Library/Preferences/
chown $userName /Users/$userName/Library/Preferences/org.mypreference.plist
done
When I run the above script it comes up with the following error:
cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... target_directory
chown: admin: No such file or directory
chown: admin/Library/Preferences/org.mypreference.plist: No such file or directory
Maybe you are looking for
-
Problem on Solaris 10 Native ldap client.
Hi, I have configured the DS 5.2 on Solaris 10 and it seems to be working. I'm getting the answers from the ldapsearch command with the SSL. ./ldapsearch -h ismesl90 -p 636 -Z -P /var/ldap -D "cn=Directory Manager" -w password -b "cn=Password Policy,
-
How do I clear my MacBook Pro HD using Disk Utility?
I'm not sure if my MacBook Pro specifications are necessary, so I'll skip those for the time being, but I have a 2009 release which already had OS X 10.6 Snow Leopard on it and came with both the OS X Install DVD and Applications Install DVD for this
-
I created a document using Live Cycle Designer ES 8.2 and when I save it to a pdf form there are certain restrictions that I can't figure out. Changing The Document: Not Allowed Document Assembly: Not Allowed I am opening the pdf using Acrobat Pro 9
-
Replacing a character in a String
Hi All, How can I replace a character ' which appears in a String into \'
-
XSLT transformations vs JSP (performance)
Hi, Does anyone know of any benchmarking study that would compare performance of those 2 technologies? Thanks for help!!!!