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 offrem DESKCLEAN.BAT MAKES DAILY FOLDER FOR WORKING FILES - UNcomment DEBUGFLAG to troubleshoot / pause:set debugflag=ANYTHING:set PAUSEFLAG=ANYTHINGIF NOT "%DEBUGFLAG%"=="" ECHO ON
setlocal
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 set newdir=_hold_%timestamp% - RATHER THAN HUNT FOR THIS LINE 
rem DEEPER, ASSIGN PREFIX / FOLDER NAME NEXT LINE
  SET DIRPREFIX=
 rem has Day of Week from below "rem set xdate=%xdate:~4%"
rem makedir with timestamp - the source for the odd string manipulators below is cmd's "help for" and "help if"
: below - remove in sequence, colon, period, space, slash (replace
 rem with underscore) then last two remove trailing 1/100ths of second and leading day of week
:xtime 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%
rem set newdir=_%timestamp%
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   ~

Leave a Reply

Your email address will not be published. Required fields are marked *