Move file to new folder if it does not exist already

I have tried what feels like a million ways to do this and none of them are working like I want.
A file will be placed in folder 1 with a unique case number as the file name. IE 12345675.txt
If the data in the file is changed a new file with the same file name will be placed out again that contains the updated info (for now I don't care about the update.)
I want powershell to look for all the .txt files in folder 1 and compare them to the .txt files in folder 2 to see if that file name already exist.
If it does not exist, I want to send a email with the content of the file and then move the file from folder 1 to folder 2.
If it does exist then only move the file to folder 2 and overwrite the file that is already there.
Sample:
$folder1="C:\inetpub\cgi-bin" # Where Application will place incident file
$folder2="C:\incidents"       # Once file is processed it is moved here
$folder1Files=dir $folder1\*.txt    # Find all txt files in folder1
$folder2Files=dir $folder2\*.txt    # Find all txt files in folder2
$files = Get-ChildItem $folder1\*.txt   # Get all file that end with .txt
foreach ($file in $files){
    $testfile="$folder2\$file"    #I know there is something wrong here but can think of how to fix.
    if (!(Test-Path $testfile)){
                                Write-Host "NEW - Sending Page"
                                $to = "email address 1"
                                $from = "email address 2"
                                $subject = "Pre Alert"
                                $body = Get-Content -Path C:\inetpub\cgi-bin\*.txt
                                $smtpServer = "mail.domain2.com"
                                $smtpClient = New-Object Net.Mail.SmtpClient($smtpServer, 587)
                                $smtpClient.EnableSsl = $false
                                $smtpClient.Credentials = New-Object System.Net.NetworkCredential("Username",
"Password")
                                $smtpClient.Send($from, $to, $subject, $body)
                                Write-Host "Moving File"        
                                Move-Item -Path 'C:\inetpub\cgi-bin\$file' -Destination 'C:\incidents'
-verbose
                        else{
                                Remove-Item $file -include "*.txt"

$testfile="$folder2\$file"
What you're asking PowerShell to do there is to make a string which will start with the value of $folder2 (which you set earlier as a string) and then the value of $file, which is a document on the file system.
PowerShell is pretty good at changing a value from one form to another (in technical terms, 'casting') but it's always best to help it along where possible.
Why don't you try adding a 'Write-Host' line to say which file you're processing, and another line to say what file you're checking for. That should show you if you're building that string correctly or if you need to modify it.
For now comment out the email section and just try to get it to tell you if the file already exists or not. Once you've got that done then try to build out the email bit. The trick is always to build small steps in Scripts and only move on once you've tested
a section.
$folder1="C:\inetpub\cgi-bin" # Where Application will place incident file
$folder2="C:\incidents" # Once file is processed it is moved here
$folder1Files=dir $folder1\*.txt # Find all txt files in folder1
$folder2Files=dir $folder2\*.txt # Find all txt files in folder2
$files = Get-ChildItem $folder1\*.txt # Get all file that end with .txt
foreach ($file in $files){
$testfile="$folder2\$file" #I know there is something wrong here but can think of how to fix.
Write-Host "Checking for file at $testFile"
if (!(Test-Path $testfile)){
#Slightly modified
Write-Host "NEW - Sending Page " $file.Name
# $to = "email address 1"
# $from = "email address 2"
# $subject = "Pre Alert"
# $body = Get-Content -Path C:\inetpub\cgi-bin\*.txt
# $smtpServer = "mail.domain2.com"
# $smtpClient = New-Object Net.Mail.SmtpClient($smtpServer, 587)
# $smtpClient.EnableSsl = $false
# $smtpClient.Credentials = New-Object System.Net.NetworkCredential("Username", "Password")
# $smtpClient.Send($from, $to, $subject, $body)
Write-Host "Moving File"
Move-Item -Path 'C:\inetpub\cgi-bin\$file' -Destination 'C:\incidents' -verbose
else{ Write-Host "File found, skipping and deleting new file"
Remove-Item $file -include "*.txt"

Similar Messages

  • Create Save to folder if it does not exist

    I have a script that will save a file to a folder up one level.  In other words if the original file was in client/jpg I wanted it saved in client/digipics.  The client folder will always have a different name.
    I want to add code that will create the "digipics" folder if it does not exist.  Here is what I have so far that works as long as I have the "digipics" folder already created:
    #target photoshop
    var AD = app.activeDocument;
    var imgName = AD.name;
    var CurrentFolder = activeDocument.path;
    var parentFolder = decodeURI(activeDocument.path.parent);
    // Write file up one level into "digipics"
    saveFile = new File(parentFolder + '/' + "digipics" + "/" + imgName)
    saveOptions = new JPEGSaveOptions();
    saveOptions.embedColorProfile = true;
    saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
    saveOptions.matte = MatteType.NONE;
    saveOptions.quality = 8;
    AD.saveAs(saveFile, saveOptions, true,Extension.LOWERCASE);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    What code can I add as an IF statemnt incase I forget to create the folder first.  It would create the folder then save to it.

    #target photoshop
    var AD = app.activeDocument;
    var imgName = AD.name;
    var CurrentFolder = activeDocument.path;
    var parentFolder = decodeURI(activeDocument.path.parent);
    var digiFolder = new Folder(parentFolder + '/' + "digipics");
    if (digiFolder.exists == false) digiFolder.create();
    // Write file up one level into "digipics"
    saveFile = new File(digiFolder + "/" + imgName)
    saveOptions = new JPEGSaveOptions();
    saveOptions.embedColorProfile = true;
    saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
    saveOptions.matte = MatteType.NONE;
    saveOptions.quality = 8;
    AD.saveAs(saveFile, saveOptions, true,Extension.LOWERCASE);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    Should do the job…

  • Endpoint Protection error: The source folder for content does not exist.

    I have a single SCCM 2012 SP1 CU4 server running on Windows Server 2012.
    I have been using this for a little more than a month for Endpoint Protection and Windows Updates.
    I just recently started seeing that my Endpoint Deployment Package has Failed.  I click on "Content Status" and select the Endpoint package (which again shows Failed).  I click on "View Status" and I get this
    message in the "Error" tab:
    The source folder for content does not exist.
    The Asset Details point to the exact location  that does not exist:
    The source directory "\\<server>\updates\endpoint\6bd81fde-3a3f-4aa9-bf70-ba007891ca68" for package "<package>" does not exist. 
    I didn't change anything related to this, and that directory path (\\server\updates\endpoint) is
    shared and is populated with a lot of other folders. 
    Is this possibly just a bad update file?  Should I manually create that sub-folder that it says is missing?
    Any help would be great!  Thanks!

    Thanks for the quick reply, Torsten.  (I often forget which logs to check for certain things).
    There are six lines (3 errors -- in italics below) in the log around the same time frame.  They read:
    The source directory \\sccm-corp\updates\endpoint\6bd81fde-3a3f-4aa9-bf70-ba007891ca68 doesn't exist or the SMS service cannot access it, Win32 last error = 2    SMS_DISTRIBUTION_MANAGER    5/27/2014 11:54:46 AM  
     5920 (0x1720)
    STATMSG: ID=2306 SEV=E LEV=M SOURCE="SMS Server" COMP="SMS_DISTRIBUTION_MANAGER" SYS=SCCM-Corp.pdcarea.lcl SITE=PDC PID=6008 TID=5920 GMTDATE=Tue May 27 16:54:46.962 2014 ISTR0="\\sccm-corp\updates\endpoint\6bd81fde-3a3f-4aa9-bf70-ba007891ca68" ISTR1="PDC00063"
    ISTR2="" ISTR3="" ISTR4="" ISTR5="" ISTR6="" ISTR7="" ISTR8="" ISTR9="" NUMATTRS=1 AID0=400 AVAL0="PDC00063"    SMS_DISTRIBUTION_MANAGER    5/27/2014 11:54:46 AM    5920 (0x1720)
    Failed to take snapshot of one or more contents in package PDC00063    SMS_DISTRIBUTION_MANAGER    5/27/2014 11:54:46 AM    5920 (0x1720)
    CDistributionSrcSQL::UpdateAvailableVersion PackageID=PDC00063, Version=10, Status=2302    SMS_DISTRIBUTION_MANAGER    5/27/2014 11:54:46 AM    5920 (0x1720)
    STATMSG: ID=2302 SEV=E LEV=M SOURCE="SMS Server" COMP="SMS_DISTRIBUTION_MANAGER" SYS=SCCM-Corp.pdcarea.lcl SITE=PDC PID=6008 TID=5920 GMTDATE=Tue May 27 16:54:46.990 2014 ISTR0="Endpoint Protection Definition Updates" ISTR1="PDC00063" ISTR2="" ISTR3=""
    ISTR4="" ISTR5="" ISTR6="" ISTR7="" ISTR8="" ISTR9="" NUMATTRS=1 AID0=400 AVAL0="PDC00063"    SMS_DISTRIBUTION_MANAGER    5/27/2014 11:54:46 AM    5920 (0x1720)
    Failed to process package PDC00063 after 33 retries, will retry 67 more times    SMS_DISTRIBUTION_MANAGER    5/27/2014 11:54:47 AM    5920 (0x1720)

  • I can create a New Folder, but it does not appear under my 'Inbox'.

    I have made sure that under 'View', that my bullet is next to show 'All' folders. I make the new folder to show up as a subfolder of my inbox, but it does not appear. I try to do it again and it states that one already exists????????????????????????
    I cannot figure out what is Wrong!!!!!!!
    Jackie

    OMG - thank you for your help!!!!!!!!!!!! I did not realize that the inbox folder was collapsed and not expanded. The new folders I made are there!
    THANK YOU!!!!!!!!!!!!!!!!

  • Can't upload to FTP Host - 'Folder on server does not exist'

    I haven't tried updating my site for about a month now. I went onto Muse last night and while uploading to the FTP Host, it kept freezing at about 66% while handling the image files.
    This was odd because I'd never had this problem before, but I noticed there was an update, so I decided to get Muse 2014.2, as maybe this could fix my problem.
    I made the same changes to my site and went to upload to FTP Host. After convincing Muse my details were correct (kept being told I had been timed out and my username or password was wrong) I was finally connected to the FTP server. However, my 'Folder on Server' (httpdocs) doesn't seem to exist according to Muse.
    I spoke to GoDaddy's support team for over an hour as we tried variations on the httpdocs folder and we had no idea why Muse wasn't accepting this (they also checked the file exists). They tried Filezilla and that was fine, so it's obviously a problem with Muse. I asked if I should just click on the option to create the httpdocs folder, but GoDaddy advised against it.
    I tried contacting the Adobe Customer Care chat thing, but I don't even know what's happening with that ("chat is unavailable . . . we'll be with you shortly" . . . eh?)
    If anyone has a solution to either my problem on the old Muse or this new problem with Muse 2014.2 (ideally this one) then that would be great.
    Also, I'm only using Muse because it cuts out all the complex stuff, so go easy on me when explaining anything that isn't "you just need to click this"

    UPDATE: I uninstalled both versions of Muse and re-installed the 2014.2 version to see if that would work, but it still doesn't think the httpdocs file exists.
    (As a result of uninstalling the old Muse, my problem regarding the freezing at 66% is now irrelevant. Just need help with Muse not accepting the httpdocs folder)

  • Backups arent completing with error cant find folder or it does not exist

    Hello, 
    Lenovo X1 Carbon, windows 7 pro 64bit. Core i5, 8GB RAM, 256 GB SSD. No DVD player. 500 GB External USB 3.0 Hard drive. 
    My backups aren't completing while using Windows Backup and Restore (WBaR). It says it can't find a folder that doesn't exist on a drive that doesn't exist(e.g. 'D:\X1\Desktop\folder_name')  I have a ultrabook from Lenovo, there is no D: drive. there
    is the C: Drive and the Lenovo Recovery drive (Q:). However, the folder name matches a folder that WAS on my desktop ('C:\[USER]\Desktop\folder_name')the first time that I used WBaR. 
    At first, I thought it was that folder, so I moved it to the Recycle bin. Then I tried moving it to a documents folder. Same error. So, then I thought it had to do with Carbonite and Dropbox. So I turned both of them off. No joy. 
    I tried searching for a folder named X1 using the command line. No luck. 
    I found this support article at http://support.microsoft.com/kb/979281, but none of these scenarios match mine. I have exhaustively searched for someone who had a problem with a Drive letter being assigned to Windows backup that doesn't exist on their
    computer. But no joy. 
    Can anyone help me? I don't think this is serious, but it is annoying, since WBaR doesn't list when my last backup was because of the problem. Plus, I'm worried about whether it will work when I need to recover files. 
    Original title
    "Windows Backup skipped D:\X1\Desktop\[folder] because it cannot be found on drive D:\." Drive D doesn't exist

    Hi,
    Please turn off backup and turn on to relocate the backup place as your USB drive.
    As I known, it's impossible to backup the files on the same partition, so C drive is system drive and impossible for your backup.
    Post back your event log related to this issue here for our research.
    Kate Li
    TechNet Community Support

  • The file /_controltemplates/15/ does not exist

    Hi Everyone.
    We are planning to migrate from share point 2010 to SharePoint 2013.So we have created one POC environment to test the customizations(master pages,Page layouts,web parts,site definition,Site templates) in SharePoint 2013.We have installed Visual Studio 2012
    to convert VS2010 solution.We have done with the converstion from VS2010 solutions to VS2012.
    We have followed all the below steps to test the same functionality.
    1.Install Visual Studio 2012 and reopen solution in VS 2012
    2.Change .NET Framework version to  v4.5
    3.Update existing reference of Microsoft.SharePoint.dll to "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI". (may need to other dlls reference as well)
    4.Add a property ‘SharePointVersion =”15.0"’ in <Solution> element in the manifest file. (otherwise it gets installed into SharePoint 14 location)
    5.Update "_layouts" folder with "_layouts/15" reference.
    6.Update "CONTROLTEMPLATES" with "CONTROLTEMPLATES/15"
    6.Build your solution, deploy and Test.
    After successful deployment we are not able to add the web part to the page.We are getting an error like the following.
    The file '/_controltemplates/15/{Project folder}/{web part Folder}/{Web PartUserControl}' does not exist.
    Any one can help me on this issue.
    Thanks in advance
    Regards,
    Anil

    Hi Everyone.
    We are planning to migrate from share point 2010 to SharePoint 2013.So we have created one POC environment to test the customizations(master pages,Page layouts,web parts,site definition,Site templates) in SharePoint 2013.We have installed Visual Studio 2012
    to convert VS2010 solution.We have done with the converstion from VS2010 solutions to VS2012.
    We have followed all the below steps to test the same functionality.
    1.Install Visual Studio 2012 and reopen solution in VS 2012
    2.Change .NET Framework version to  v4.5
    3.Update existing reference of Microsoft.SharePoint.dll to "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI". (may need to other dlls reference as well)
    4.Add a property ‘SharePointVersion =”15.0"’ in <Solution> element in the manifest file. (otherwise it gets installed into SharePoint 14 location)
    5.Update "_layouts" folder with "_layouts/15" reference.
    6.Update "CONTROLTEMPLATES" with "CONTROLTEMPLATES/15"
    6.Build your solution, deploy and Test.
    After successful deployment we are not able to add the web part to the page.We are getting an error like the following.
    The file '/_controltemplates/15/{Project folder}/{web part Folder}/{Web PartUserControl}' does not exist.
    Any one can help me on this issue.
    Thanks in advance
    Regards,
    Anil

  • Upload file via document Manager in taskflow: error the file does not exist

    Hi,
    I have a page that include document manager. I am able to upload file to UCM server via one user signon. Then I created a new user in UCM. With this new user, whenever I try to upload a file, the file name that I entered keeps getting blanked out when I click 'Upload'. The I will get an error that
    'Error: A value is required:
    The file you are trying to upload does not exist or is empty
    Select a non-empty file and retry.
    Enter a file name and location'
    Do you have any idea what I missed for setting up this new user?
    Thanks,
    Charunee

    Found that I need to assigned role in WLS to that new user also.
    After that, this issue is resolved.

  • 'Stream requested does not exist' error while importing MPEG-2 file.

    Hi.
    I received the following error when attempting to import an MPEG-2 file as a Timeline:
    'Stream requested does not exist'
    What does this mean?
    Thanks,
    William Johnston

    Let me introduce you to the SEARCH link
    http://www.adobeforums.com/cgi-bin/webx?126@@.1de98ec0
    Go there and enter
    Stream requested does not exist
    As well as this message thread, there are over a dozen other messages you may read
    If you don't find a solution... come back here and post more information
    Always provide DETAILED computer and software information, including all hardware and software brand/model and version numbers, with DETAILS about the input files you are using and any output files you wish to create, plus read
    How to ask a GOOD Forum question with COMPLETE information
    First message gives 5 specific suggestions (you may do #5 for FREE, depending on your problem and purchase date) and then tells how to ask a question in such a manner that you provide all the information that you WILL be asked, for anyone to be able to provide an answer
    Second message has advice, and links, concerning optimizing a computer for video editing
    Third message concerns things that USED to work, but now do not (and more questions to answer)
    Also, for Premiere Pro, check the
    Wiki FAQ

  • Error promoting reports using LCM: The kind 'Note' does not exist

    Hi,
    We are using BOXI3.1 with FixPack1.3 installed on a Windows 2003 Enterprise environment. We have installed Life Cycle Management for version management and content promotion. Our environment coneist of three server installations (Development, Test and Production).
    Our problem is that we are not able to promote reports from one environment to another. Wee are getting two different kind of errors, depending on the scenario:
    Error 1: For actual promotion
    Commit Status=Commit attempted and failed, Promotion Status=Failure : com.businessobjects.lcm.utilities.LCMException: com.businessobjects.sdk.biar.exception.XSDException$UnknownKindException: The kind 'Note' does not exist in the CMS. (FWM 04030)
    Error 2: For test promotion
    Commit Status=Commit attempted and failed, Promotion Status=Failure : com.businessobjects.lcm.utilities.LCMException: com.businessobjects.sdk.biar.exception.XSDException$ImportParsingException: Import file parsing exception occurred : 'Item 'ALLOW_DISCUSSION_THREADS' does not exist in enumeration 'Note_RightEnum'. (FWM 04016)' (FWM 04009) cause:com.businessobjects.sdk.biar.exception.XSDException$InvalidEnumItemException: Item 'ALLOW_DISCUSSION_THREADS' does not exist in enumeration 'Note_RightEnum'. (FWM 04016) detail:Import file parsing exception occurred : 'Item 'ALLOW_DISCUSSION_THREADS' does not exist in enumeration 'Note_RightEnum'. (FWM 04016)' (FWM 04009) Item 'ALLOW_DISCUSSION_THREADS' does not exist in enumeration 'Note_RightEnum'. (FWM 04016)
    This error happens for borth the Administrator user, and a user who are a member of the Administrator user group.
    We have tested following:
    1. Verify the user has at least view right for Custom Access Levels in CMC
    2. Verify the user has the 'Allow discussion thread' on the Note content on Top Level security in 'Folder' in CMC.
    3. We are getting the same error when exporting to BIAR
    4. The user have Full control of the LCM folder
    5. We have tested promotion with security option enabled
    We have also a test report where we have set Full Control and allow discussion thread explicit on the user.
    Have anyone experienced the same error and a suggestion for what can be wrong?
    Jøran
    Edited by: Jøran Kleiven on Feb 24, 2010 3:22 PM

    Hi,
    Could you tell me which table this object are in? I tried ci_infoobjects and ci_systemobjects, but it returned null.
    Jøran

  • Visual studio 2012 the name "initializeControl" does not exist in the namespace in visual WebPart

    Hi All,
    I'm trying to create a visual webpart in SharePoint 2013 using Visual Studio 2012 and I am seeing that the file ascx.g.cs
    is missing and i have this error in file ascx.cs : the name "initializeControl" does not exist in the namespace.
    And like i said i use VS2012 Ultimate
    Can anyone Help me please!!!
    thanks.

    In most scenarios this is caused by some error in code preventing Visual Studio from generating the designer file. You could try to undo the latest changes and see whether the item is being generated or not. Additionally you could try checking if the custom
    tool is still associated with the Visual Web Part SPI in the Properties Window.
    w: http://blog.mastykarz.nl | t:
    @waldekm | c: http://mavention.codeplex.com | c:
    http://mavention.nl

  • Node id does not exist for the current application server id  on forms

    Hi,
    We have a Two node RAC setup on which Oracle e-business suite R12.0.6 is setup
    We have CP and DB on two RAC nodes and Forms and Web on two separate server(non-RAC)
    while opening oracle forms we are getting" Node id does not exist for the current application server id "
    on checking Concurrent manager logfile we founf no error, we matched Application Server id from DBC file of all the 4 nodes with application table
    Fnd_nodes... which matches ( there is no mismatch of application server id) .
    We have also tried commenting the application server id in dbc file and executed adgendbc.sh to regenarate dbc file but we are facing the same issue.
    Also tried to clear setup with fnd_conc_clone.clean setup and again executing autoconfig on db and application tier but no result yet.
    Can some one guide as to which file has this message "Node id does not exist for the current application server id "
    and what could be the reason for this.
    Help is appreciated.
    Regards,
    Milan

    I already tried the mentioned metalink note id but it did not work.What did you try exactly?
    Can u help out as from where am i getting the message "Node id does not exist for the current application server id" It is already mentioned in the doc referenced above -- From the dbc file under $FND_SECURE directory.
    i mean from which file does the above message comes.Please clean FND_NODES table as per (How to Clean Nonexistent Nodes or IP Addresses From FND_NODES [ID 260887.1]), run AutoConfig on the database tier then on the application tier and check then.
    Thanks,
    Hussein

  • I tried to rename a file, it gave me an error message (can't remember the number - 43??) and then the file disappeared from the original folder. When I do a search, the file comes up under the new name, but it does not show a path, and even though preview

    I tried to rename a file, it gave me an error message (can't remember the number - 43??) and then the file disappeared from the original folder. When I do a search, the file comes up under the new name, but it does not show a path, and even though preview shows the contents, I can't open the document (Powerpoint) and I can't move the document. I tried "Copy" and paste but it doesn't work. I tried "Share" with Airdrop and iChat, but the file is inaccessible. When i try to rename the file, it says the filename is too long.
    When I try to open it, it says the alias is not good, and asks if I want to fix the alias. I'm afraid to do that and lose all access to this document.
    Right now, it feels like a ghost document - it is on the computer intact, but it is in an undisclosed location and inaccessible.
    Please help!!

    I was able to resolve this by repairing permissions, even though no permissions error was listed specifically for that file.
    I could also have recovered it through Time Machine, but I'm interested in knowing how not to have this happen again!
    I was afraid of rebooting and possibly losing track even of the ghost.
    I did not try EasyFind - I'll keep that in mind next time.
    Thanks for all the comments.

  • Lightroom 5 file edited in photoshop cc 2014 does not appear back next to original after save. Is anyone else having this issue? If so what is the fix.  The edited image appears back in lightroom in a new folder.

    Lightroom 5 file edited in photoshop cc 2014 does not appear back next to original after save. Is anyone else having this issue? If so what is the fix.  The edited image appears back in lightroom in a new folder.

    I'm performing a normal "Save", not "Save As". Work flow I'm using is as follows:  Select photo in Lightroom 5.7 >" Edit In" Photoshop CC 2014 > (after working on photo is PS) > Save > close PS. Photo returns to Lightroom 5.7 in a new folder rather than next to the original. Prior to purchasing the monthly plan and upgrading to PS CC 2014, I performed this same work flow using Lightroom 5.6 and Photoshop CS6 without any issues.
    Just for fun... I attempted to move the edited file back into the original folder. I received a prompt that said the file already existed in the original folder, however I can't see it except the new folder that LR created. I tried several different sort orders, etc without any success.
    *** Follow up: Was unable to resolve the issue using Photoshop CC 2014. Uninstalled PS CC 2014 and went back to using Photoshop CS6. Return trips from LR 5.7 to Photoshop is now performing as it should: returning edited photo back to the original folder in LR 5 and placing next to the original image.
    Should anyone have a suggestion on getting Photoshop CC 2014 to do the same, I would love to be educated.
    Thanks for the help, dj_paige.

  • How to move files from one folder to another folder in webdynpro java for sap portal

    Dear Experts,
    I wan to move files from one folder to another folder in SAP portal 7.3 programmatically in webdynpro java.
    My requirement is in my portal 1000 transport packages is their. Now i want to move 1 to 200 TP's into Archive folder.
    Can you please help me how to do in through portal or wd java ...
    Regards
    Chakri

    Hello,
    Do you know what the difference between copying a file this way :
    ** Fast & simple file copy. */
    public static void copy(File source, File dest) throws IOException {
    FileChannel in = null, out = null;
    try {         
    in = new FileInputStream(source).getChannel();
    out = new FileOutputStream(dest).getChannel();
    long size = in.size();
    MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
    out.write(buf);
    } finally {
    if (in != null) in.close();
    if (out != null) out.close();
    ================SECOND WAY============
    AND THIS WAY:
    // Move file (src) to File/directory dest.
    public static synchronized void move(File src, File dest) throws FileNotFoundException, IOException {
    copy(src, dest);
    src.delete();
    // Copy file (src) to File/directory dest.
    public static synchronized void copy(File src, File dest) throws IOException {
    InputStream in = new FileInputStream(src);
    OutputStream out = new FileOutputStream(dest);
    // Transfer bytes from in to out
    byte[] buf = new byte[1024];
    int len;
    while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
    in.close();
    out.close();
    And which is better? I read up on what each kind of does but still a bit unclear as to when it is good to use which.
    Thanks in advance,
    JavaGirl

Maybe you are looking for

  • Photoshop 7 will not recognize my fire wire drives as scratch disks

    Photoshop 7 will not recognize my fire wire drives as scratch disks. Using Photosop 7.0.1 & Mac OS X Tiger on G4 Tower with AGP Graphics. Any Ideas? Thanks in advance, Tom

  • Selecting string from all the tables in databse

    Hi All, I need a help in finding the data from all the database tables at one time using single query. For e.g. I wanna search a string 'ABC' in all the database tables for a schema. I want to find out,which all tables (in either of its columns) cont

  • RFC function module with call transaction  and Import memory ID

    Hi, I am calling RFC function module from R/3 which exists in BW. In BW stand alone function module works fine. When I am Calling from R/3 it is not working, Can you tell me is it because of the below code, And suggest if any corrections required. I

  • Can I print an objects fields' values in a loop without having to cast?

    Hi, I have a Class with about 30 (public)fields and I need to print the values of each of them to a file. I tried the getFields() method of the Class object, but couldn't get the desired result, especially that the documentation says no order is guar

  • Setting Tab Order

    Hi All,       I have a Subform with one TextField, and it flows, say 10 number of times i.e. 9 instances are added. When using Tab, the control only goes to the origianal Subform, and not to its instances. How to set the Tab Order to the Text Fields