简体   繁体   中英

change directory in batch script past a folder without a name

I have a folder without a name and an image where I keep most of my important documents at work (away from prying eyes).

I'm writing a batch script, from command prompt I can change directory to any folder past that folder, but when I duplicate the exact same command in a batch script it doesnt seem to work. I get the error "System cannot find the file specified" error.

here is my script.

@echo on
net use Z: /delete
pause
net use Z: "\\agfs1\IS\Monthly reports"
timeout /t 5
cd "C:\Users\lalderman\Desktop\ \_Monthly reports"
copy /Y "Monthly Report - Lee.txt" Z:\
pause

after the cd it gives me the error. I've tried it with and without quotes.

Well,

First, for clarification, from what I see above, you have a directory with the name, " " (eg the directory's name is a space.).

And, I think you are having a conflict in the different ways things are read in the Microsoft platform you are using; namely between how the Command Prompt reads spaces as part of a path versus how the batch script parser is reading those same spaces in the path.

Now, I just tried doing a Change Directory operation in a batch file on WinXP across and under a folder that was just named " ", and it worked as expected.

@echo on 
pause
echo "Starting..."
cd "C:\DLS\Tests\ \chkthis"
pause
echo "Did we get it?"

So, now the question is; which platform are you trying to do this on?

HTH.

Use the 8dot3 name. In your desktop directory, type dir /x /ad to see what the 8dot3 name of your "directory without a name" is and use that in your script path.

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