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: How to create a current date folder using batch file?

21 Nov 2011   #1
nikhil2686

Window 7 Pro 32 bit
 
 
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"

xcopy "%USERPROFILE%\Desktop" "%USERPROFILE%\My Documents\backup\%curr_date%_backup" /D/S/H/V/C/F/K/Y

for /d /r "%USERPROFILE%\Desktop" %%x in (*) do rd /s /q "%%x"
for /r "%USERPROFILE%\Desktop" %%x in (*) do del /f "%%x"

copy "%USERPROFILE%\My Documents\backup\%curr_date%_backup\*.lnk" "%USERPROFILE%\Desktop\"

del /q "%USERPROFILE%\My Documents\backup\%curr_date%_backup\*.lnk"


In the first line I am creating a folder with current date, e.g. curr_date_backup. Second, copying the contents of Desktop to the newly created folder. Third, deleting directories from the desktop. Forth, deleting files from the desktop. fifth, Copy back all the shortcuts to the desktop. sixth, deleting all the shortcuts from Current date folder.

This batch file is working perfectly in Windows XP. It works in win 7 also but the problem is that the name of the current date folder created by first command is "Desktop". when I use command prompt to check the name, the name is correct. I checked the properties of the folder the correct is there also. But in windows the name doesn't match with the expected one.

I need help. Kindly tell me what's going on? why window 7 is showing directory name as "Desktop"? Is there any other way for creating folder in win7 using batch file.

thanks




Attached Thumbnails
How to create a current date folder using batch file?-1.jpg  
Attached Images
How to create a current date folder using batch file?-2.jpg 
Attached Files
File Type: bat 1.bat (523 Bytes, 107 views)
My System SpecsSystem Spec
.
21 Nov 2011   #2
Ztruker

Windows 10 Pro X64
 
 

Works for me, at least the first two commands work as advertised.

test.bat
set curr_date=%DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2%
echo %curr_date%"

mkdir "%USERPROFILE%\My Documents\backup\%curr_date%_backup"
dir "%USERPROFILE%\My Documents\backup"



Quote:
C:\Users\xxxxxxx>set curr_date=2011-11-21

C:\Users\xxxxxxx>echo 2011-11-21"
2011-11-21"

C:\Users\xxxxxxx>mkdir "C:\Users\xxxxxxx\My Documents\backup\2011-11-21_backup"

C:\Users\xxxxxxx>dir "C:\Users\xxxxxxx\My Documents\backup"
Volume in drive C is D370_C
Volume Serial Number is C89E-70E8

Directory of C:\Users\xxxxxxx\My Documents\backup

11/21/2011 01:30 PM <DIR> .
11/21/2011 01:30 PM <DIR> ..
11/21/2011 01:30 PM <DIR> 2011-11-21_backup
0 File(s) 0 bytes
3 Dir(s) 28,082,577,408 bytes free
My System SpecsSystem Spec
22 Nov 2011   #3
nikhil2686

Window 7 Pro 32 bit
 
 

Run "1.bat".
My System SpecsSystem Spec
.

22 Nov 2011   #4
Ztruker

Windows 10 Pro X64
 
 

No, I won't run 1.bat, sorry. You said "It works in win 7 also but the problem is that the name of the current date folder created by first command is "Desktop". I took the first two lines and put them in a batch file and they work correctly. They did not create a Desktop folder.

What happens if you run just the first two lines? Does it work correctly?
My System SpecsSystem Spec
22 Nov 2011   #5
nikhil2686

Window 7 Pro 32 bit
 
 

xcopy behavior is the the problem.
My System SpecsSystem Spec
23 Nov 2011   #6
Ztruker

Windows 10 Pro X64
 
 

Okay, tried it as far as running xcopy and ity works correctly for me. I end up with a

C:\Users\xxxxxxxx\My Documents\backup\2011-11-23_backup

xcopy then copied everything from my Desktop directory into it correctly.

I'm not seeing the problem you are describing.
My System SpecsSystem Spec
24 Nov 2011   #7
nikhil2686

Window 7 Pro 32 bit
 
 

May be it depends on windows. I am running this batch file on 32 bit OS.
My System SpecsSystem Spec
24 Nov 2011   #8
Corazon

Windows 7 Professional SP1 32-bit
 
 

I think the problem might be you have a hidden desktop.ini file in your Desktop folder.

If I'm right, then this file gets copied along with everything else into your backup folder, and when looking at the backup folder with Explorer, the desktop.ini file (its backup, that is) instructs Explorer to show the backup folder as "Desktop".

See if a desktop.ini file is present in your backup folder. If yes, delete it. Does this change Explorer's behavior?

If yes, you've found the problem. From there, all you need to do is modify the xcopy commandline arguments to exclude "desktop.ini" from being copied and you're all set.
My System SpecsSystem Spec
24 Nov 2011   #9
nikhil2686

Window 7 Pro 32 bit
 
 

thanks for the info...
My System SpecsSystem Spec
Reply

 How to create a current date folder using batch file?




Thread Tools




Similar help and support threads
Thread Forum
i want to create a batch file to disable changing system time and date
hi, i want to create a batch file to disable changing system time and date hope some one will sure help me thank you
System Security
How to create a shortcut to batch file one folder up
Hello I have been trying to create a shortcut to launch a batch file one folder up from the shortcut location. I have been able to do this using and intermediate batch file in the same folder as the shortcut as follows: Intermediate.bat: @echo off FOR %%V IN ("%~dp0..\") DO set curdrv=%%~dpV...
Performance & Maintenance
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...
General Discussion
Is there a Script or batch file that can create folders by date range
I was wondering if there was a way to create a set of folders in a specific directory according to a date range that i input. ie. Select start date 2011 10 01 select end date 2012 10 01 Select Output path of c:\users\XXXX\desktop\export data
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


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 08:11.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App