Copying Files while Excluding Files without an extension

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 14 hours 44 minutes ago
January 11th, 2014 11:56pm

copy .* c:\test
Free Windows Admin Tool Kit Click here and download it now
January 12th, 2014 12:13am

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            Rdios

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

January 12th, 2014 12:29am

copy .* c:\tes
Free Windows Admin Tool Kit Click here and download it now
January 12th, 2014 9:30pm

copy .* c:\test

January 12th, 2014 11:39pm

copy .* c:\test

Free Windows Admin Tool Kit Click here and download it now
January 13th, 2014 12:31am

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}

January 13th, 2014 12:44am

copy .* c:\test

Free Windows Admin Tool Kit Click here and download it now
January 13th, 2014 4:12pm

Why do you want a list of files but only files that only have extensions? What problem is this solving for you?

Bill

January 13th, 2014 4:17pm

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 }


Free Windows Admin Tool Kit Click here and download it now
January 13th, 2014 4:20pm

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.

January 13th, 2014 4:27pm

See David Wyatt's last answer - *.* -file on PowerShell 3.0 or *.* | where-object { -not $_.PSIsContainer } for earlier versions.

Bill

Free Windows Admin Tool Kit Click here and download it now
January 13th, 2014 4:47pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics