简体   繁体   中英

I want to hide and create a folder. But it doesn't create a folder

I want to make a little File/Folder Hide/Unhide batch program. So I want to make a hidden folder the folder creating code looks like that:

set setupPath="C:\Users\%username%\Desktop\FiFoH"
IF NOT EXIST %setupPath% (
cd "C:\Users\%username%\Desktop"
mkdir FiFoH
attrib +S +H %setupPath%
cd %setupPath%
echo. >> log.txt
)

But it doesn't create a folder.

Your issue is in cd "C:\\Users\\%username%\\Desktop" and cd %setupPath%. The cd command will not accept full paths unless you use the /D switch. The following code should work:

set setupPath="%userprofile%\Desktop\FiFoH"
IF NOT EXIST %setupPath% (
cd /D "%userprofile%\Desktop"
mkdir FiFoH
attrib +S +H %setupPath%
cd /D %setupPath%
echo. >> log.txt
)

Also, you don't need to use the %username% variable and can go a more direct route to your desktop folder by using %userprofile% to get to the user profile (which in your case would be C:\\Users\\%username%).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM