topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday April 19, 2024, 6:31 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Must be too easy ? or Windows 10 does not like it  (Read 5803 times)

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
Must be too easy ? or Windows 10 does not like it
« on: September 15, 2015, 04:01 PM »
This is something that 4WD already wrote about a year ago and i have used it as needed on a Windows 7 system.  But i cannot get it to work for some reason on windows 10 with the same requirements.

It should be as simple as a one liner  (or maybe 2)

In a given directory there are sub-folders named "A" to "Z".  In this same directory many people just dump their files without alphabetically filing them. 
This little batch script just went through the loose files in the folder, extracted the first letter of any file it found and moved that file to the correct folder based on its first letter.

So "C:\Lots-Of-Files\Smith, Adam.txt" would get moved into "C:\Lots-Of-Files\S\Smith, Adam.txt" with the overwrite switch to ON and no permission asking.
the "A"to "Z" sub folders are already there and in that same directory.  It would be preferable to just set the variables to be run from the local directory
(of course the ends up moving the bat file too but that is OK, i name it "ZZfiler.bat" so I know where to go get it next time i need it :)

anyway, 4WD's solution was a little more complex as it would even create the alphabetic sub-folders when needed which is not really required as every directory i have to use this on already has A to Z in it.  And like I said, it worked fine on Win7 but on Win 10 it just blinks and does nothing.?

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,643
    • View Profile
    • Donate to Member
Re: Must be too easy ? or Windows 10 does not like it
« Reply #1 on: September 15, 2015, 07:58 PM »
Sounds like an access problem, ie. not having the right permissions.

Powershell version:

AlphaMove.ps1
Code: PowerShell [Select]
  1. $items = (Get-ChildItem -File)
  2.  
  3. for ($i = 0; $i -lt $items.Count; $i++) {
  4.   if ($items[$i] -match "^[0-9 ]") {
  5.     $path = "A"
  6.   } else {
  7.     $path = $items[$i].BaseName.Substring(0, 1)
  8.   }
  9.   if ($items[$i].BaseName -ne "AlphaMove") {
  10.     if (!(Test-Path $path)) { New-Item $path.ToUpper() -ItemType Directory | Out-Null }
  11.     $dest = ".\" + $path
  12.     Move-Item $items[$i] $dest
  13.   }
  14. }

Run it from within the folder ... and it won't move itself ;)

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,186
    • View Profile
    • Donate to Member
Re: Must be too easy ? or Windows 10 does not like it
« Reply #2 on: September 15, 2015, 08:52 PM »
if you're going to run a powershell script from within the folder, don't forget to give yourself execute permissions using the Set-ExecutionPolicy cmdlet.  They have it pretty much locked down in Windows 10.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,643
    • View Profile
    • Donate to Member
Re: Must be too easy ? or Windows 10 does not like it
« Reply #3 on: September 15, 2015, 11:14 PM »
err yeah, forgot that bit - if you'd rather not worry about that, since it has no input/output requirements you could run it from a shortcut, (in the same folder), with the Target set as:

Code: Text [Select]
  1. %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -noprofile -executionpolicy bypass -File "AlphaMove.ps1"

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,646
    • View Profile
    • Donate to Member
Re: Must be too easy ? or Windows 10 does not like it
« Reply #4 on: September 16, 2015, 06:51 AM »
In a given directory there are sub-folders named "A" to "Z".  In this same directory many people just dump their files without alphabetically filing them.  This little batch script just went through the loose files in the folder, extracted the first letter of any file it found and moved that file to the correct folder based on its first letter.


Scripting is nice, but IMO you're solving the wrong problem. The permissions on the parent directory should be set as below for both Authenticated and Domain Users.

Permissions Demo.jpg

Subfolder permissions will need to be reset (to once again restore write access) after doing this, but the end result is forced honesty. Because nobody can create files/folders in the root on the tree...which forces them to put stuff where it belongs. They can however delete/move their existing junk to where it belongs. And if - by chance - you don't trust them to do the cleaning...omit the delete permissions.

We had huge problems here when I first started, because of the exact reason you describe here ... And then suddenly one day...the problem just vanished (by force..). :D


[/BOFH Mode]

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,643
    • View Profile
    • Donate to Member
Re: Must be too easy ? or Windows 10 does not like it
« Reply #5 on: September 16, 2015, 07:37 AM »
^ That was one of the original suggestions ;)

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,646
    • View Profile
    • Donate to Member
Re: Must be too easy ? or Windows 10 does not like it
« Reply #6 on: September 16, 2015, 11:11 AM »
^ That was one of the original suggestions ;)

Understood, but it is still worth revisiting. Because every time Quest runs the script, he is accepting responsibility for whatever happens next. And this has nothing to do with the script itself ...(I know you got skills)... It's just that it's almost always a matter of time before user X decides to pitch a fit because their Uber Important stuff got put some place they couldn't find it. So instead of teaching the "pet" zombie to play catch, and then hope it doesn't eat one of the children on a bad day. I just think it best to shoot it in the head and be done with it completely.

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,186
    • View Profile
    • Donate to Member
Re: Must be too easy ? or Windows 10 does not like it
« Reply #7 on: September 16, 2015, 11:27 AM »
So instead of teaching the "pet" zombie to play catch, and then hope it doesn't eat one of the children on a bad day. I just think it best to shoot it in the head and be done with it completely.

That's some serious imagery there.  Fido much?

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,646
    • View Profile
    • Donate to Member
Re: Must be too easy ? or Windows 10 does not like it
« Reply #8 on: September 16, 2015, 01:22 PM »
So instead of teaching the "pet" zombie to play catch, and then hope it doesn't eat one of the children on a bad day. I just think it best to shoot it in the head and be done with it completely.

That's some serious imagery there.  Fido much?

A decade or so of being an Admin will do that to ya. That and I'd just gotten back from surveying a new client's network that had been - set up wrong and subsequently - eaten alive by a CryptoLocker variant. Everybody wants to cut corners and cry about budgets until shit goes completely off the rails...and then suddenly they're 'All Ears' about WTF to do with the mess.

This guy is now looking at ~1,000 man-hours rebuilding a database from paper files ... Because there just wasn't time to lock anything down properly...or do backups for that matter.

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
Re: Must be too easy ? or Windows 10 does not like it
« Reply #9 on: September 17, 2015, 05:00 PM »
OMG wraith!  NO!  STOIC!n  what  the heck  all of ya!

I am LMAO!

You made my day today that was a very good eh...
tet-a-te or what you say?  Hmm Verbal Parrying

I need somethign to drink now.  :) ;D ;D

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,540
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Must be too easy ? or Windows 10 does not like it
« Reply #10 on: September 18, 2015, 05:33 PM »
...This guy is now looking at ~1,000 man-hours rebuilding a database from paper files ... Because there just wasn't time to lock anything down properly...or do backups for that matter.
_________________________________

Interesting. Look at it from an accounting perspective.
So, it's necessary to rebuild a mission-critical database from scratch. right? And he's the only guy that can do it?
Let's see now...that's equivalent to 1000/40=25 40-hour working weeks of paid effort...
That's 25/48*100=52% of a working year.
Just for the sake of argument, let's say he's paid at the rate of $50/hr...
He's looking at 1000*50=$50,000 pay, right there.    :o
Of course, once it's been rebuilt, there'll be an awful lot of extra work to verify/correct data quality, and design, set up, test and operate all those new backup/recovery/network and contingency processes that weren't there before - so's the database can't be lost so easily again, see?

I could be wrong, of course, without knowing the context and details, but this incident seems like it could offer some good job continuity/security for at least a year in these uncertain times.
If he's an employee, then maybe the guy is pretty smart.
If the job's done properly, it will be a long-lasting risk mitigation strategy for the company data and he'll be a hero. It sounds like it should've been done years ago.
« Last Edit: September 18, 2015, 05:54 PM by IainB »