none
Copying Files while Excluding Files without an extension RRS feed

  • Question

  • I'm blanking out on this one.  

    How can I copy files that only have an extension?  (Windows 2008R2/Windows7)

    Is Powershell my only route?  Seems like there should be an easier way to do this.


    • Edited by jlcg Monday, January 13, 2014 8:49 PM
    Saturday, January 11, 2014 8:56 PM

Answers

  • A pattern of *.* should work fine, as far as I know.

    Get-ChildItem *.* -File

    Edit:  The -File switch requires at least PowerShell 3.0.  If you're using PowerShell 2.0, you'd need to use the old technique of filtering with Where-Object:

    Get-ChildItem *.* | Where-Object { -not $_.PSIsContainer }


    Monday, January 13, 2014 9:15 PM

All replies

  • copy .* c:\test

    ¯\_(ツ)_/¯

    Saturday, January 11, 2014 9:13 PM
  • Reverse method:

    PS C:\scripts> 1..12|%{$z=('?'*$_);dir $z}

        Directory: C:\scripts

    Mode                LastWriteTime     Length Name

    ----                -------------     ------ ----

    -a---        11/24/2013   6:20 AM          8 -1

    d----         9/25/2013  12:26 PM            wf1

    d----        12/29/2013   9:46 AM            wmi

    d----         8/26/2013   3:10 AM            test

    -a---          9/9/2013   1:22 PM          0 dhcp

    -a---          9/9/2013  10:32 AM         87 True

    -a---         1/11/2014   4:24 PM         16 xxxx

    d----        12/28/2013   2:24 PM            43024

    d----         6/26/2013   7:22 AM            test1

    -a---        12/12/2013   2:28 AM          7 query

    d----          9/2/2013   9:21 AM            Rádios

    d----         8/13/2013  12:13 PM            tester

    d----        11/28/2013  12:45 PM            acltest

    d----          9/5/2013   7:58 AM            doctest

    d----         10/4/2013   6:39 AM            Outlook

    -a---         9/21/2013  10:24 AM       1713 popcorn

    d----         10/1/2013  12:21 AM            Pictures

    d----         9/23/2013  12:41 AM            PsTracker

    d----         6/22/2013   9:23 PM            iTextSharp

    d----         9/21/2013   1:58 AM            test space

    -a---        12/31/2013   9:40 AM      22509 Get-NTPTime

    -a---          9/3/2013   8:58 AM        832 Get-ArpTable



    ¯\_(ツ)_/¯


    • Edited by jrv Saturday, January 11, 2014 9:31 PM
    Saturday, January 11, 2014 9:29 PM
  • copy .* c:\test

    ¯\_(ツ)_/¯

    That only copies files without filenames or rather leads with a .
    Sunday, January 12, 2014 6:30 PM
  • copy .* c:\test


    ¯\_(ツ)_/¯

    That only copies files without filenames or rather leads with a .

    That is exactly what you asked for.


    ¯\_(ツ)_/¯

    Sunday, January 12, 2014 8:39 PM
  • copy .* c:\test


    ¯\_(ツ)_/¯

    That only copies files without filenames or rather leads with a .

    That is exactly what you asked for.


    ¯\_(ツ)_/¯


    Based on the subject and what's been said so far, I assume he meant to ask "How do I copy only files that have an extension?", rather than "How do I copy files that only have an extension?"
    Sunday, January 12, 2014 9:31 PM
  • I would write that "How do I copy all files except those that do not have an extension.

    The question was asked to exclusively different ways and I posted and answer to both versions as I understood that.

    dir *|?{$_.Extension}


    ¯\_(ツ)_/¯

    Sunday, January 12, 2014 9:44 PM
  • copy .* c:\test


    ¯\_(ツ)_/¯

    That only copies files without filenames or rather leads with a .

    That is exactly what you asked for.


    ¯\_(ツ)_/¯


    Based on the subject and what's been said so far, I assume he meant to ask "How do I copy only files that have an extension?", rather than "How do I copy files that only have an extension?"

    Yes, I did, sorry if that wasn't clear.

    Using Powershell, I can Get-ChildItem and filter for only extensions but short of using % I'm struggling getting that output to a single line so I can pass it as an argument to a command line, like robocopy..

    Monday, January 13, 2014 9:07 PM
  • Why do you want a list of files but only files that only have extensions? What problem is this solving for you?

    Bill

    Monday, January 13, 2014 9:11 PM
    Moderator
  • A pattern of *.* should work fine, as far as I know.

    Get-ChildItem *.* -File

    Edit:  The -File switch requires at least PowerShell 3.0.  If you're using PowerShell 2.0, you'd need to use the old technique of filtering with Where-Object:

    Get-ChildItem *.* | Where-Object { -not $_.PSIsContainer }


    Monday, January 13, 2014 9:15 PM
  • Why do you want a list of files but only files that only have extensions? What problem is this solving for you?

    Bill

    Copying files from a CIFS share on one server to another location for backup purposes.

    Basically, the files without a valid extension are massive and don't need to be backed up.  Unfortunately, the original location is an appliance and the backup methodology (via NDMP) can't exclude by filenames since it doesn't look at that level, it sees everything as a Filesystem.

    If I copy the files that do need to be backed up (anything with an extension) to a Windows Server then I can back up that location.

    Monday, January 13, 2014 9:22 PM
  • See David Wyatt's last answer - *.* -file on PowerShell 3.0 or *.* | where-object { -not $_.PSIsContainer } for earlier versions.

    Bill

    Monday, January 13, 2014 9:42 PM
    Moderator
  • JRV already gave the simplest most straight forward answer.  To carry it further you could pipe the results to the copy command and not need Robocopy.

    dir *|?{$_.Extension} | copy -destination F:\newfolder

    This will get all of the files in the current folder  that have an extension and none that do not,  then copy them to F:\newfolder

    What it basically says is get  a list of all of the files,  pick only the ones with an extension and then copy them somwhere else.

    You will have to change the paths match your environment.

    Jrussell97

    Tuesday, January 14, 2014 2:22 PM