Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: batch&task to create new folder and move all desktop file to it

27 May 2015   #1
Robopolo

32 bit, all versions work in an office
 
 
batch&task to create new folder and move all desktop file to it

hi so work in an recruitment office and im trying to create a batch file that the computers can run on a schedule to create a folder with that days date on it and move all files from the desktop to that folder( also created on the desktop), i want the code to only move files and leave folders and shortcuts unaffected

this is what i've got so far.

Quote:
cd desktop

for /f "tokens=1-3 delims=/" %%a in ("%date%") do md "%%a_%%b_%%c"
mkdir c:\users\training\desktop\%date:/=%

MOVE c:\users\training1\desktop\*.* c:\users\training1\desktop\%date:/=%
right now it is making the folder but not moving anything i know it has something to do with the \%date:/=%

il need this batch file to run from a hidden location so that 1. the students dont mess with it and 2. so the batch doesn't move itself from the desktop. also the computers all have different user names so if i could get something that will make "training1" what ever the current logged in user is so i don't have to rewrite the batch for each of the 60 or so computers we have.


My System SpecsSystem Spec
.
27 May 2015   #2
MilesAhead

Windows 7 32 bit
 
 

Especially with files and folders I find AHK easier to figure out than batch. You can download the free AutoHotkey scripting language here:
AutoHotkey

Here is a script to get you started. I commented out the actual deletions. You can run it and see the desktop files that would be moved in a msgbox. Each loop it asks if you want to quit to escape the tedium. Once you are sure it will work as expected comment out the lines with msgbox and uncomment the FileMove line

If anything gets moved into the folder that shouldn't be you can just drag it back during testing. The variable A_Desktop is the user's desktop directory so the script should work without editing as far as that goes.

Note: free to use at your own risk.

Code:
FormatTime,FolderName,,yyyy_MM_dd
FolderName := A_Desktop "\" FolderName
FileCreateDir,%FolderName%
Loop %A_Desktop%\*.*
{
  If (A_LoopFileName = "desktop.ini")
    continue
  If (SubStr(A_LoopFileName,-3) = ".lnk")
    continue
  ; FileMove,%A_LoopFileLongPath%,%FolderName%
  MsgBox % A_LoopFileName
  MsgBox, 4388, Quit Loop, Quit Loop?
  IfMsgBox,Yes
    ExitApp
}
My System SpecsSystem Spec
28 May 2015   #3
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Anything is more easier to figure out than batch.

But here's a batch solution that does a similar task.

Code:
@echo off

:: Move all files on the users Desktop to Desktop\%date_format%. 

set date_format=dd_MM_yyyy
set exclude_extensions=".ini",

goto :main

:get_username
setlocal
	for /f "tokens=2 delims=\" %%I in (' wmic computersystem get username /value ') do for /f "delims=" %%J in ("%%~I") do (
		set "user=%%~J"
	)
endlocal & set "user=%USER%"
goto :eof

:get_date date_format_string
setlocal
	for /f "usebackq delims=" %%I in (` powershell "(get-date).ToString( '%~1' )" `) do (
		set datestring=%%I
	)
endlocal & set "datestring=%DATESTRING%"
goto :eof

:SUB filename
setlocal EnableDelayedExpansion
	if "%~1"=="%~2" goto :SUB_continue
	for %%I in ("%~2") do (
		for %%K in (%EXCLUDE_EXTENSIONS%) do (
			set ext=%%~K& set ext=.!EXT:.=!
			if "%%~xI"=="!EXT!" goto :SUB_continue
		)
	)
	move %2 "C:\Users\%USER%\Desktop\%DATESTRING%"
	:SUB_continue
endlocal
goto :eof

:main
call :get_username
call :get_date "%DATE_FORMAT:"=%"
if not exist "C:\Users\%USER%\Desktop\%DATESTRING%" ( md "C:\Users\%USER%\Desktop\%DATESTRING%" ) else ( exit /b 1 )
for /f "delims=" %%I in (' dir /a:-d /b "C:\Users\%USER%\Desktop" ') do (
	call :SUB %0 "C:\Users\%USER%\Desktop\%%~I"
)
My System SpecsSystem Spec
.

28 May 2015   #4
MilesAhead

Windows 7 32 bit
 
 

Quote   Quote: Originally Posted by Pyprohly View Post
Anything is more easier to figure out than batch.
Even Lisp?
My System SpecsSystem Spec
28 May 2015   #5
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Quote   Quote: Originally Posted by MilesAhead View Post
Quote   Quote: Originally Posted by Pyprohly View Post
Anything is more easier to figure out than batch.
Even Lisp?
Even LOLCODE.
My System SpecsSystem Spec
28 May 2015   #6
MilesAhead

Windows 7 32 bit
 
 

Quote   Quote: Originally Posted by Pyprohly View Post
Quote   Quote: Originally Posted by MilesAhead View Post
Quote   Quote: Originally Posted by Pyprohly View Post
Anything is more easier to figure out than batch.
Even Lisp?
Even LOLCODE.
Never ran into it before. All caps. Way gauche.
My System SpecsSystem Spec
Reply

 batch&task to create new folder and move all desktop file to it




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Move files from original folder to existing folders - w batch file?
My files have a format of "ID_date_time.d7d Ex: 11111-5_2013_10_07_142149.d7d The ID is 1111-5 and was tested 10/7/2013 at 2:21:49 PM and the file extension is always .d7d The local files are automatically saved here by the program generating the data: C:\Local\Data I want them copied...
General Discussion
Batch file to move desktop icons so ALL are sorted.
Win7 stores desktop icons in two different folders: C:\Users\Public\Public Desktop C:\Users\UserName\Desktop This results in two groups of sorted icons on the desktop. I want to move all of the icons in the "C:\Users\Public\Public Desktop" to the "C:\Users\UserName\Desktop". This will...
General Discussion
How to create a current date folder using batch file?
Hi I am using following batch file for cleaning the desktop and also for taking backup of desktop: @echo off set curr_date=%DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2% mkdir "%USERPROFILE%\My Documents\backup\%curr_date%_backup"
General Discussion
Batch file to create a folder with name of the time.
I'm trying to write a batch file that when run creates a folder named "Backup" followed by the time it was created, and then copies files to that folder. When I run md "C:\Users\MasterControlProgram\Documents\MC Server With Backup\Backups\Backup %DATE%\" xcopy /e /v /y...
Backup and Restore
Batch file to move (many) duplicted folder contents - Help!!
Hope I can explain my difficulty. I have duplicated folders album name for all my music files. As there is quite a considerable number I wondered if it was possible to batch file (automate) the process. I can not delete "d" as this would delete all the tracks. What I need to do is move the...
General Discussion
How to create a batch file that will move files based on the file type
How to create a batch file that will move files based on the file type? My Requirement : I need a batch file to copy all .doc files in all my HardDisk to a removable disk say (Z: drive) . Can anyone make it possible using a batch file?Please...Its urgent...
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 16:12.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App