Quick cleaning up desktop from old files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Jonny
Posts: 5
Joined: 26 Jan 2018 05:50

Quick cleaning up desktop from old files

#1 Post by Jonny » 26 Jan 2018 05:57

Guys,

Please your kind help with a small batch file that is doing following:

1. Creates a new folder under path : "C:\Users\jonny\xxx\yyy\temp" in format DDMMMYYYY (ex. 26JAN2018)
2. Moving into this new folder all files located on Desktop

That's all..

You help will be much appreciated.

The next phase is to schedule PC to do this automatically.


Jonny
Posts: 5
Joined: 26 Jan 2018 05:50

Re: Quick cleaning up desktop from old files

#3 Post by Jonny » 26 Jan 2018 14:41

Is this a joke? Sorry for not having time to learn all the commands.
May someone just help with the solution?

Thanks

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Quick cleaning up desktop from old files

#4 Post by aGerman » 26 Jan 2018 18:11

Jonny wrote:
26 Jan 2018 14:41
Is this a joke? Sorry for not having time to learn all the commands.
DosTips is not RentACoder. So yes, we expect that you take the time to learn Batch as well as you expect that the volunteers take their free time to help you with your code.
Jonny wrote:
26 Jan 2018 14:41
May someone just help with the solution?

Code: Select all

@echo off &setlocal
for %%i in ("01=JAN","02=FEB","03=MAR","04=APR","05=MAY","06=JUN","07=JUL","08=AUG","09=SEP","10=OCT","11=NOV","12=DEC") do set "M%%~i"
for /f "delims=." %%i in ('wmic os get LocalDateTime /value') do for /f %%j in ("%%i") do set "%%j"
set "YYYY=%LocalDateTime:~,4%" &call set "MMM=%%M%LocalDateTime:~4,2%%%" &set "DD=%LocalDateTime:~6,2%"
2>nul md "%userprofile%\xxx\yyy\temp\%DD%%MMM%%YYYY%"
for /f "delims=" %%i in ('dir /b "%userprofile%\desktop\*.*"^|findstr /vie "\.lnk \.url"') do (
  move "%userprofile%\desktop\%%i" "%userprofile%\xxx\yyy\temp\%DD%%MMM%%YYYY%\"
)
Steffen

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Quick cleaning up desktop from old files

#5 Post by ShadowThief » 26 Jan 2018 18:12


Jonny
Posts: 5
Joined: 26 Jan 2018 05:50

Re: Quick cleaning up desktop from old files

#6 Post by Jonny » 27 Jan 2018 05:10

Thank you, Steffen, I will try this and let you know.

Jonny
Posts: 5
Joined: 26 Jan 2018 05:50

Re: Quick cleaning up desktop from old files

#7 Post by Jonny » 02 Feb 2018 12:31

This looked to me too much complicated, so I've built a new one:
Looks at this , much more readable solution:

Code: Select all

@echo off &setlocal
md "C:\Users\YYY\OneDrive - XXX\Documents\temp\%DATE:~3,2%%DATE:~0,2%%DATE:~8,4%
move "C:\Users\YYY\OneDrive - XXX\Desktop\*.*" "C:\Users\YYY\OneDrive - XXX\Documents\temp\%DATE:~3,2%%DATE:~0,2%%DATE:~8,4%
pause
What's the difference?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Quick cleaning up desktop from old files

#8 Post by Squashman » 02 Feb 2018 12:43

Jonny wrote:
02 Feb 2018 12:31
This looked to me too much complicated, so I've built a new one:
Looks at this , much more readable solution:

Code: Select all

@echo off &setlocal
md "C:\Users\YYY\OneDrive - XXX\Documents\temp\%DATE:~3,2%%DATE:~0,2%%DATE:~8,4%
move "C:\Users\YYY\OneDrive - XXX\Desktop\*.*" "C:\Users\YYY\OneDrive - XXX\Documents\temp\%DATE:~3,2%%DATE:~0,2%%DATE:~8,4%
pause
What's the difference?
You changed the scope of your request then.

Your original request said to do the date like this.
Jonny wrote:
26 Jan 2018 05:57
1. Creates a new folder under path : "C:\Users\jonny\xxx\yyy\temp" in format DDMMMYYYY (ex. 26JAN2018)
Your new code will only work on computers that have the same regional settings as you. The code provided to you is region independent.

Post Reply