Batch: Clean Windows Desktop

Runs from any location - moves designated files into a (new) folder on the Windows desktop  named with  today's date.

@echo off
setlocal
rem DESKCLEAN.BAT MAKES DAILY FOLDER FOR WORKING FILES - 
rem UNcomment DEBUGFLAG to troubleshoot / pause
:set debugflag=ANYTHING
:set PAUSEFLAG=ANYTHING
IF NOT "%DEBUGFLAG%"=="" ECHO ON
pushd %userprofile%\Desktop
set filestring = *.pdf;*.txt;*.log;*.xls*;*.sql;*.bak;*.java;*.class;*.jp*;*.gif;*.png;*.bku;*.bkk;*.bmp;*.htm*;*.php;*.css;*.pl;*.py;*.rb;*.doc*;*.ppt*
  rem leave DIRPREFIX blank to create folder with timestamp only 
SET DIRPREFIX=hold
  rem has Day of Week from below "rem set xdate=%xdate:~4%"
  rem makedir with timestamp - the documentation for 
  rem the cryptic string manipulators below is 
  rem cmd's "help for" and "help if"
: below - the SET statements remove from mmm dd, yyyy hh:mm
: in sequence, colon, period, space, slash (replace
: with underscore) 
: then last two remove trailing 1/100ths of second 
: and remove the leading day of week
: xtime is not used unless appended to timestamp
   set xtime=%time::=%
   set xtime=%xtime:.=_%
   set xtime=%xtime: =0%
   set xtime=%xtime:~0,-3%
   set xdate=%date: =_%
   set xdate=%xdate:/=_%rem set xdate=%xdate:~4%
   set timestamp=%xdate%
   set newdir=%DIRPREFIX%_%timestamp%
 rem set newdir=_%timestamp%
 rem remark out above line if you want day of week included at front

rem set timestamp=%xdate%_%xtime% rem this includes timestamp seconds, making unique folder - OMIT to have only one folder per day

for %%x in (%filestring%) do if exist "%%x" if not exist "%newdir%" md "%newdir%"
for %%x in (%filestring%) do if exist "%%x" move "%%x" %newdir%
rem  for %%x in (*.tif;*.jpg;*.jpg;*.gif;*.pdf;*.txt;*.log;*.xls*;*.sql;*.bak;*.bku)
 if exist "%%x" if not exist %newdir% md %newdir%
rem for %%x in (*.tif;*.jpg;*.jpg;*.gif;*.pdf;*.txt;*.log;*.xls*;*.sql;*.bak;*.bku)
if exist "%%x" move "%%x" %newdir%
IF "%DEBUGFLAG%"=="" GOTO END
pause<
:END
popd: UNcomment any below to pause and see variables at work
:set n
:SET D
echo END OF BATCH FILE %0
IF NOT "%PAUSEFLAG%"=="" PAUSE

endlocal

Optionally Uncomment line(s) 5 and/or 6 to watch it work

 
set debugflag=dbf
: (or anything except blank)

set PAUSEFLAG= pflag