Announcement

Collapse
No announcement yet.

Copy files after certain creation date and retain folder structure

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Copy files after certain creation date and retain folder structure

    hi,

    i'm looking for a script or something that can transverse through our file server, copy all files after certain creation date to another location, and retain the folder structure at the same time.

    i thought about robocopy before, but seems it only uses the last modified date or last accessed date of a file

    hope someone can shed some light.

    many thanks
    a.

  • #2
    Re: Copy files after certain creation date and retain folder structure

    Robocopy will do this. Use the /MAXAGE:n parameter as described in the documentation along with the /E switch to copy the folder structure.
    A recent poll suggests that 6 out of 7 dwarfs are not happy

    Comment


    • #3
      Re: Copy files after certain creation date and retain folder structure

      With Powershell you can get the creation time using this example
      Code:
      Get-Item C:\Windows\notepad.exe |select CreationTime
      Make a for loop around it to search through a folder structure and copy or move the files to a location
      Marcel
      Technical Consultant
      Netherlands
      http://www.phetios.com
      http://blog.nessus.nl

      MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
      "No matter how secure, there is always the human factor."

      "Enjoy life today, tomorrow may never come."
      "If you're going through hell, keep going. ~Winston Churchill"

      Comment


      • #4
        Re: Copy files after certain creation date and retain folder structure

        Originally posted by Blood View Post
        Robocopy will do this. Use the /MAXAGE:n parameter as described in the documentation along with the /E switch to copy the folder structure.

        unfortunately the maxage parameter is based on the last modified date instead of created date of a file.

        Comment


        • #5
          Re: Copy files after certain creation date and retain folder structure

          Originally posted by Dumber View Post
          With Powershell you can get the creation time using this example
          Code:
          Get-Item C:\Windows\notepad.exe |select CreationTime
          Make a for loop around it to search through a folder structure and copy or move the files to a location

          i'm really not familiar with powershell, would you mind to give me more detail on how to get this to work?

          Comment


          • #6
            Re: Copy files after certain creation date and retain folder structure

            Hi
            I'm not a PowerShell guru, but this is an example how it can be done. Yet it's on your own risk to use it, so Test, test, test, test it! ....

            Code:
            $path="c:\temp"
            $destination = "c:\test"
            
            ## setting date 1 day back
            $CurrentDate = (get-date).AddDays(-1)
            
            $AllFiles = Get-ChildItem -Path $path -recurse 
            foreach ($File in $AllFiles){
            	write-host $File.Fullname
            		if ($File.PSIsContainer -eq $true){
            			$Folder = $File.Name
            			New-Item ($destination + "\" + $Folder) -itemtype directory
            		
            		}
            		if ($File.CreationTime -ge $currentDate -and $file.PSIsContainer -eq $false){
            			if ($File.FullName -match $Folder){
            				copy-item $File.Fullname ($destination + "\" + $Folder) -Recurse -Force
            				}
            			else{
            				copy-item $File.Fullname $destination -Recurse -Force
            				}
            		}
            }
            Last edited by Dumber; 20th September 2012, 16:53.
            Marcel
            Technical Consultant
            Netherlands
            http://www.phetios.com
            http://blog.nessus.nl

            MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
            "No matter how secure, there is always the human factor."

            "Enjoy life today, tomorrow may never come."
            "If you're going through hell, keep going. ~Winston Churchill"

            Comment

            Working...
            X