Hack Forums
[Shell] Desktop Organizer - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Shell] Desktop Organizer (/showthread.php?tid=5106224)



Desktop Organizer - wurd - Dec 23, 2015

Short but sweet code, drag and drop a mess of programs and the code organizes the programs by their extensions.
Code
@echo off & setlocal EnableDelayedExpansion
for %%A in (%*) do (
set /a x+=1
set prog!x!=%%A
set progext!x!=%%~xA
)
for /l %%A in (1,1,!x!) do (
if "!progext%%A!"=="" set progext%%A=Folders
if not exist "%cd%\!progext%%A!" md "%cd%\!progext%%A!"
for /l %%B in (%%A,1,!x!) do (
if exist "!prog%%B!" if "!progext%%A!"=="!progext%%B!" move !prog%%B! !progext%%A!
))
cls & echo Finished. Cleaned !x! Programs up.
Pause > nul
Merry Christmas 🤝


* - White Light - Dec 23, 2015

Just taking a quick glance through it, I've got a small suggestion. You should take a look at using a standard FOR loop (no extra switches) to loop over %* It has all the arguments already, so you don't need to shift for each one.


* - wurd - Dec 23, 2015

(Dec 23, 2015 10:44 PM)White Light Wrote:  Just taking a quick glance through it, I've got a small suggestion. You should take a look at using a standard FOR loop (no extra switches) to loop over %* It has all the arguments already, so you don't need to shift for each one.
I'll look into it in the morning, way too tired to function right now


I've been trying to use the standard for loop but I keep getting errors when I try to loop through the extensions
Code
for %%A in (%~x*) do set /a "y+=1" & set "progext!x!=%%A"
but when I do(below) it works, keep in mind I need to grab the extension since the program organizes based off the extension.
Code
for %%A in (%*) do set /a "x+=1" & set "prog!x!=%%A"
can someone point out my mistake?


* - 0xDEAD10CC - Dec 25, 2015

As far as I can tell, you need to loop through %*, not %~x*, and from there you would do %%~xA...

Ex:
Code
FOR %%G IN (%*) DO (
  ECHO %%~xG
)



* - White Light - Dec 25, 2015

(Dec 23, 2015 11:00 PM)wurd Wrote:  I'll look into it in the morning, way too tired to function right now


I've been trying to use the standard for loop but I keep getting errors when I try to loop through the extensions
Code
for %%A in (%~x*) do set /a "y+=1" & set "progext!x!=%%A"
but when I do(below) it works, keep in mind I need to grab the extension since the program organizes based off the extension.
Code
for %%A in (%*) do set /a "x+=1" & set "prog!x!=%%A"
can someone point out my mistake?


As 0xDEAD10CC said, you should loop through %* and then use the x modifier on each individual result. There's no way for the script to natively use modifiers on %* without first parsing through the individual parameters.


* - wurd - Dec 28, 2015

Fixed. Thanks for the help guys


* - Stamina_Client - Jan 2, 2016

I'm new to coding can you tell me exactly what this is suppost to do? i ran it and it said applications cleaned so i guess it work

-stamina


* - Nakamoto. - Jan 2, 2016

(Jan 2, 2016 12:58 PM)Stamina_Client Wrote:  I'm new to coding can you tell me exactly what this is suppost to do? i ran it and it said applications cleaned so i guess it work

-stamina

it organizes them by filetype, so all like filetypes are grouped up.


* - wurd - Jan 4, 2016

(Jan 2, 2016 12:58 PM)Stamina_Client Wrote:  I'm new to coding can you tell me exactly what this is suppost to do? i ran it and it said applications cleaned so i guess it work
-stamina
Click and drag the programs you want to be cleaned onto the batch file
[Image: 864908bd079cae5e1e969fdca95b7a75.gif]


* - Lightning827 - Jan 4, 2016

you should mabey add a for loop to this


* - annikk.exe - Jan 4, 2016

(Jan 4, 2016 05:06 PM)wurd Wrote:  Click and drag the programs you want to be cleaned onto the batch file
[Image: 864908bd079cae5e1e969fdca95b7a75.gif]

Awesome demo gif. :> Very good to show people how it works!