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

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 Windows 7 using batch file.

thanks




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

21 Nov 2011   #2

Windows 8 Core 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

Window 7 Pro 32 bit
 
 

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


22 Nov 2011   #4

Windows 8 Core 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

Window 7 Pro 32 bit
 
 

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

Windows 8 Core 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

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

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

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




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 05:24 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33