myITforum.com Community Forum myITforum.com Community Forum

Home  Forums  Blogs  Live Support chat  Search Articles  Wiki  FAQ  Email Lists  Register  Login  My Profile  Inbox  Address Book  My Subscription  My Forums 

Photo Gallery  Member List  Search  Calendars  FAQ  Ticket List  Log Out

All Forums RSS Feed Subscription:


  


Managing files/folders in Powershell

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
  Printable Version
All Forums >> [Scripting Technologies] >> Windows PowerShell >> Managing files/folders in Powershell Page: [1]
Login
Message << Older Topic   Newer Topic >>
Managing files/folders in Powershell - 8/13/2008 12:14:29 PM   
lcox

 

Posts: 82
Score: 0
Joined: 12/10/2003
Status: offline
I have a very perplexing problem. I have some folders on a corp "dumping ground" server that can be accessed by Unix, Macs, and PCs. There are some folders and files that show up in Windows Explorer which can be enumerated, when you try to delete them it says that..."Cannot delete file: Cannot read from the source file or disk". Using Powershell I see that the file attributes are set to "darhs". Within Powershell, I try to list the directory and those folders won't show up. Using the -force, then they do show up. But after that, anything I try to do to them I get an error message saying it couldn't find the item; deleting, changing attributes, etc. It appears they may have been put up there with a Mac or Unix box using Samba. Using different Windows-based tools has not proven successful. Got any ideas??
Post #: 1
RE: Managing files/folders in Powershell - 8/13/2008 12:58:04 PM   
martylist

 

Posts: 41
Score: 0
Joined: 6/10/2005
From: Colorado, USA
Status: offline
Are there any unusual characters in the path?  Paste some examples of the file names, with the full path. From cmd.exe (not powerShell.exe), instead of:    del "c:\myfolder\myfile.ext"try this:    del "\\?\c:\myfolder\myfile.ext" and if it fails, post the exact error message. 

(in reply to lcox)
Post #: 2
RE: Managing files/folders in Powershell - 8/13/2008 12:59:31 PM   
gmaynard

 

Posts: 23
Score: 0
Joined: 9/9/2004
Status: offline
Have you checked your permissions on those files/folders?

(in reply to lcox)
Post #: 3
RE: Managing files/folders in Powershell - 8/13/2008 1:15:55 PM   
lcox

 

Posts: 82
Score: 0
Joined: 12/10/2003
Status: offline
Thanks for the quick response....this is driving me crazy...so close, but....
As SysAdmin on the box, I have taken ownership of the folder and files under it; no effect on being able to do anything with them.
The folders in question have names like: lastname, firstname [it appears there is a space after lastname and the comma]. [There also sometimes appears to be a  space after firstname, but Explorer ignores it of course].
From a CMD window, at the root folder level with the server mapped to drive X, and confirming that the directory will list when typing in: dir -force (it won't list with a simple "Dir"), I type in these different variations:
x: del lastname, firstname = Could not find x:\lastname
x: del "lastname, firstname" = Could not find x:\lastname, firstname
x: del "lastname, firstname " (with a space at the end) = Could not find x:\lastname, firstname
x: del " lastname, firstname" (with a space at the beginning) = Could not find x:\ lastname, firstname (yes, it placed a space at the beginning)

(in reply to martylist)
Post #: 4
RE: Managing files/folders in Powershell - 8/13/2008 1:34:06 PM   
gmaynard

 

Posts: 23
Score: 0
Joined: 9/9/2004
Status: offline
Have you tried anything besides deleting such as moving them to a new volume or changing their attributes?

(in reply to lcox)
Post #: 5
RE: Managing files/folders in Powershell - 8/13/2008 1:41:12 PM   
lcox

 

Posts: 82
Score: 0
Joined: 12/10/2003
Status: offline
Yes, Windows Explorer can enumerate, but nothing else. CMD can list but nothing else, and Powershell can list when using a -force (and thus shows the file attributes "darhs", which I think is my key to solving this). Because of this, I can't seem to have any affect on deleting, moving copying, etc.

(in reply to gmaynard)
Post #: 6
RE: Managing files/folders in Powershell - 8/13/2008 1:46:35 PM   
gmaynard

 

Posts: 23
Score: 0
Joined: 9/9/2004
Status: offline
My only other thought would be to run check disk to see if you have some corruption in your indexes. I assume all of these folders are local to the server. These folders are not DFS links or other similar redirects?

(in reply to lcox)
Post #: 7
RE: Managing files/folders in Powershell - 8/13/2008 1:53:59 PM   
lcox

 

Posts: 82
Score: 0
Joined: 12/10/2003
Status: offline
They are not redirects. It's interesting to note that subfolders listed under one of these in question that do not a space at the end of the filename can be manipulated (deleted, moved, etc). I successfully deleted one, but not the others so I can have something to work with as I continue to solve this problem. Remember, the root folder DOES have a space after the folder name (which tells me it wasn't put there by a Windows box).

< Message edited by lcox -- 8/13/2008 1:54:37 PM >

(in reply to gmaynard)
Post #: 8
RE: Managing files/folders in Powershell - 8/13/2008 2:54:02 PM   
martylist

 

Posts: 41
Score: 0
Joined: 6/10/2005
From: Colorado, USA
Status: offline
PowerShell is probably the wrong tool for this, since all of it's file I/O is done through the .NET Framework classes which are "safe" and work with the least comon denominator across all OS versions.  Explorer will also be the wrong tool. You should be able to get rid of these with cmd.exe, for example: 
C:\Temp>md "\\?\C:\Temp\Folder with a trailing space "

C:\Temp>dir "\\?\C:\Temp\Folder with a trailing space "
Volume in drive \\?\C: is Drive C:
Volume Serial Number is 8023-C66B

Directory of \\?\C:\Temp\Folder with a trailing space

08/13/2008  12:45 PM    <DIR>          .
08/13/2008  12:45 PM    <DIR>          ..
              0 File(s)              0 bytes
              2 Dir(s)  106,337,890,304 bytes free

C:\Temp>dir "C:\Temp\Folder with a trailing space "
Volume in drive C is Drive C:
Volume Serial Number is 8023-C66B

Directory of C:\Temp

File Not Found

C:\Temp>dir "C:\Temp\Folder with a trailing space*"
Volume in drive C is Drive C:
Volume Serial Number is 8023-C66B

Directory of C:\Temp

08/13/2008  12:45 PM    <DIR>          Folder with a trailing space
              0 File(s)              0 bytes
              1 Dir(s)  106,337,890,304 bytes free

C:\Temp>rd "C:\Temp\Folder with a trailing space"
The system cannot find the file specified.

C:\Temp>rd "\\?\C:\Temp\Folder with a trailing space "

(in reply to lcox)
Post #: 9
RE: Managing files/folders in Powershell - 8/13/2008 4:01:28 PM   
lcox

 

Posts: 82
Score: 0
Joined: 12/10/2003
Status: offline
I tried this on a similar folder and got similar results; "The system cannot find the file specified."

(in reply to martylist)
Post #: 10
RE: Managing files/folders in Powershell - 8/13/2008 4:18:03 PM   
martylist

 

Posts: 41
Score: 0
Joined: 6/10/2005
From: Colorado, USA
Status: offline
Are you trying to do this remotely?  Earlier you said something about a drive mapped to x:.  You need to repair this on the console of the server, using local fixed drives like C: Try something like this, with the file names in [brackets] so it's more obvious if there's spaces.

for /f %a in ('dir /a /b "\\?\c:\myfolder\"') do @echo [%a]

attrib.exe -r -a -s -h "\\?\c:\myfolder\*"


< Message edited by martylist -- 8/13/2008 4:38:48 PM >

(in reply to lcox)
Post #: 11
RE: Managing files/folders in Powershell - 8/13/2008 5:03:04 PM   
lcox

 

Posts: 82
Score: 0
Joined: 12/10/2003
Status: offline
Wellllllll, I went to the console and tried it as well; same result. Ran a chkdsk /f /x w/o any issues or reports of problems.

(in reply to martylist)
Post #: 12
RE: Managing files/folders in Powershell - 8/13/2008 7:03:44 PM   
martylist

 

Posts: 41
Score: 0
Joined: 6/10/2005
From: Colorado, USA
Status: offline
Wellllll I'm out of ideas, unless you were to start posting the exact command lines you are running and the exact output of the commands, with exact file names, etc. (like I'm taking the time to do).  I'm done guessing.

(in reply to lcox)
Post #: 13
RE: Managing files/folders in Powershell - 8/13/2008 11:25:02 PM   
lcox

 

Posts: 82
Score: 0
Joined: 12/10/2003
Status: offline
i thought i gave you all of the commands as i used them and as you had suggested i use. the filenames are different (company sensitive, so i would hope you would understand), but the results are as they appeared on the screen.

(in reply to martylist)
Post #: 14
RE: Managing files/folders in Powershell - 8/15/2008 3:41:17 PM   
lcox

 

Posts: 82
Score: 0
Joined: 12/10/2003
Status: offline
Actually I figured it out. And I had this posted in several blogs/forums, but nobody could come up with an answer. I didn't really figure it out. I stumbled onto a program that identified the problem. It's called DelinvFile at PurgeIE.com. It took care of my problem as well as pointed out other problems I was having with unknown long file names in about 30 minutes. I've been at this for several weeks off and on. Now I have to remember all the places I placed this request to give everyone the answer.

Although the program has a nice intuitive GUI, it was instantly apparent what the problem was as soon as I launched it the app. The program displays both the short name (8.3 format) and the long name and uses that to "manage" the files/folders. Before allowing the program to do everything, I opened up a Command shell and used Del and rmdir on a couple of the identified suspect file and folders with their 8.3 names and POOF! they were gone.

I've been in IT for over 30 years and with all of the GUI-driven apps I had forgotten all about how to expose the short name for files. When I saw the Short Name column, I knew exactly what to do. ARGH!!

Now, my task is to re-engineer my Powershell script to recursively go thru the directory and those files that meet my LastAccess criteria, to use their 8.3 name to blow them away. I'm sure there is a Powershell switch in there somewhere, just need to find it.

Thanks for trying to help. It looks like I stumped a bunch of people though!  =-)

(in reply to lcox)
Post #: 15
RE: Managing files/folders in Powershell - 8/27/2008 9:52:59 AM   
SAPIENScripter

 

Posts: 100
Score: 0
Joined: 5/15/2007
From: SAPIEN Technologies
Status: offline
I ran into similar problems years ago when a web server would get hacked and directories were created with names like COM: and other reserved names that Windows couldn't delete.  I think I had to use some POSIX tools to clean them up.

Using Powershell to get the file's lastAccessTime is simple but I'm not having much luck getting the 8.3 name.


_____________________________

Jeffery Hicks
Microsoft MVP - Windows PowerShell
http://blog.SAPIEN.com
coming soon: Managing Active Directory with Windows PowerShell: TFM
followme: http://www.twitter.com/jeffHicks

(in reply to lcox)
Post #: 16
Page:   [1]
All Forums >> [Scripting Technologies] >> Windows PowerShell >> Managing files/folders in Powershell Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts



  
Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.313