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)
Similar Messages
-
How to Upload the Materials for one Plant and then copy the same to all oth
Hi All,
I am using Material Types NonStock, Service, Spare Parts and Trading.
How to Upload the Materials for one Plant and then copy the same to all other plants.
can anybody give response for this requirement.
Regards...
<b></b>Hi,
Using MM01 Only we can upload Plant Details.
If you want to extend to other plant also, Use MM01 and select Plant view and give new plant details.
If you want to copy from one plant to another plant after selecting Plant view , next screen you can select From Plant and To Plant Details.
Reward Points If it helps you.
Regards,
Murali K -
I backed up my 3GS using iTunes. I then restored the file to my new 4GS. Then I synced the apps onto the 4GS. Then I downloaded 2 custom ringtones, and attempted to sync them onto the 4GS, but it says "This Library is already synced with another phone, and if you try to sync, you will lose all of the information on the iPhone." I am a Windows user. This Sync process is VERY confusing.
How can I possibly get these two new ringtones onto the iPhone without wiping out everything else on the phone? This Sync process is nuts.
I have Backed Up the phone twice. Why would iTunes try to wipe out the phone? -
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
-
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. -
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] -
I DOWNLOAD THE NEW UPDATE IOS7 THEN IT WILL TAKE 40SEC THEN ILL WAIT FOR DOWNLOAD IT FOR ALMOST 12HRS THEN SUDDENLY IT GO BACK AGAIN IN THE START !WHAT A DISSAPOINT!!!
iOS: Importing personal photos and videos from iOS devices to your computer
iOS: Unable to import photos or device not recognized as a camera -
I'm new to Mac and I have a Mac Mini. Could you please tell me how I could paste an URL to a video downloader like "Coolmuster Video Downloader for Mac"? I can copy the url but I could not paste it on the downloader. I appreciate your help to my problem.
Is this happing because the external is formatted to PC and not mac?
Yes that is correct.
Will I need to get a mac external hard drive if I wish to continue to save my documents like this?
If you no longer use a PC you could format this drive for the Mac. However be aware that formatting a drive will erase all the data on it. So you would need someplace to copy the data off this drive to while you did the re-format and then you could copy the data back.
You could get another drive, format it for the Mac and copy the data to it. Then re-format the original drive and use it as a backup drive. Always good to have backups.
Post back with the drive type and size of the current drive, if you are doing backups now and how and if you still need to access this drive from a PC.
regards -
What should I do if the iphoto keeps on saying that "Plz wait for import to complete" when i click the close button but it is not importing photos? How can I close the iPhoto? I try to switch my mac off but it doesn't work. Thanks.
You should be able to select Force Quit from the menu beneath the Apple icon in Finder
and choose to Quit iPhoto from there, without messing up the Mac OS X in the process.
OS X - Support
Not sure if rebuilding the iPhoto library would help this issue. However if you had to
turn off the computer without the correct method (unplug, etc; instead of menu choice)
the system may have accrued damages and should be checked, maybe repaired by
use of the Disk Utility in the system. Or restart the computer in Safe Boot mode, then
run 'repair disk permissions' while it is running in that reduced mode; then restart after.
•Understanding Safe Mode - tuts+ computer skills tutorial:
http://computers.tutsplus.com/tutorials/understanding-safe-mode--mac-59897
•OS X: What is Safe Boot, Safe Mode?
Suggestions on how to use Safe Mode in article, to resolve issues, may be helpful.
There likely are other means to rectify troublesome applications, including reinstall.
Be sure to backup your music, image, video, and other work on an external drive
or suitable device as a precaution against loss should there be a hard drive failure.
iPhoto - Mac Apps - Apple Support
There should be some tips and help information using iPhoto via this tiny Support link.
Good luck & happy computing! -
I cannot close or import or any function to iphoto. I have been getting the same message for many days "Photos are being imported to the photo library. Please wait for import to complete." I do not know where the photos would be importing from. How do I get it to proceed?
After Force Quitting, as LarryHN recommended,
Select the iPhoto Library in the Finder. By default it is in your Pictures folder.
Ctrl-click or right-click the iPhoto lIbrary. Select "Show package contents" from the panel, that will pop up.
Look for a folder named "Importing" or "Import". Remove this folder, but don't touch anything else.
Then launch iPhoto again.
If iPhoto now is working again, check the folder you removed, if there are any photos that you want to keep and save them. -
Hello, I have songs that show they are "Waiting" for download from the cloud but they are greyed out. Some songs in one album are done others in the same album will not download. It is not a time function because i have been working on this for weeks. I have allowed my compter to run for days and the songs are still not accessible. I have a Match subscription and Match is working. If I click on the "Genre" link the greyed out songs show that they are ready for download from the cloud but I cannot download them. I have downloaded over 1500 other songs, so I am trying to understand what is going on here. I would appreciate any help anyone can give me.
ThanksI did think about that and if I have to I will do that, however there are about 50 songs. I have closed and reopened iTunes several times and I am sure that I have the latest version. It fails right away but I can click on the cloud download icon and download the song that it failed on ... therefore it is not that song "or any one song" causing the issue. Any ideas?
-
Hi I was in the procces of uploading photos from my phone three days ago as i have an important art project to finish today. I have tried to restart my computer log off come back on but every time i put my phone to the computer and press up load photos its comes up with "Photos are baeing import to photo library- please wait for import to complete".
There are 90 photos and this came after it uploaded a few - can you help me - i have tried to quit iphone but this keeps coming up and i need these pics imported from my phone to my computer.
please help
thank youApple menu ==> forec quit
LN -
when I download from my samsung camera, the photos do not go to the "photos" file. I have to download to "import" then copy them to a separate album. what am I doing wrong?are
Is iPhoto open when you connect the camera and are you seeing the camera in iPhoto?
If not then describe in detail how you're going about trying to import photos from your Samsung camer into your iPhoto Library. From what you've described we have no idea what's going on.
And where is this "import" folder located that you're referring to?
OT -
My Mac laptop IPhoto is "stuck" on a screen that says, "Please wait for import to complete." I can't get it to complete the task. What do I do next?
Force Quit the app. It's under the File menu.
Maybe you are looking for
-
Busted sound on T520-- pop sound
Hi. Sound has busted on T520 for a few weeks now. I can hear sound when I plug in my earphones, but windows recognizes this as a speaker, conexant 20672. I checked the "find and fix audio playback problems" in windows 7 to no avail. I believe I
-
Formatting the return value of: File(myFile).lastModified()
I'm checking file date and time stamps: myDate = File(myFile).lastModified()Is there a way to format the return value? myDate equals: 1205166439145I'd like to see something like: 03/10/2008 12:27 PMI'm using the following code to print the value: Sy
-
How do I save my numbers files as an xls for others to view with Mavericks
After upgrading to OS Mavericks, I cannot save my files as an xls for others to view that have a pc. How do I do this for others to read?
-
Installed pixel bender but it doesn't show up under filter
I am running CS5 Standard 64 bit Windows 7 Professional and downloaded and ran "pixelbenderplugin_p2_64bit_090910.mxp" that appeared to end successfully however; pixel bender doesn't show in the filters drop down list. I could not see how I directed
-
Hi, i can't find mathematics operators such as , , exc. Is there a way to write them by keyboard without externals apps?