|
Answer» Hi everyone. First post here, so I guess a quick introduction is in order. I'm Vincent, and I'm starting off learning how to make some (basic) .BAT files. I already know some C++ and Java and ActionScript etc., but I still haven't started DOS, heh.
Soooo anyways.
My first file is just trying to rename "first.txt" to "second.txt". However, I haven't GOTTEN that far because the batch file can't ever seem to find the file specified. It can find the folder the file is IN just fine, but it can't seem to find any file within that folder at all.
Code: [Select]@echo off if exist "C:\Documents and Settings\Vincent\My Documents\first.txt" ( echo Yeah ) else ( echo No ) pause That results in "No." However, if I change the PATH to "C:\Documents and Settings\Vincent\My Documents", it ECHOS "Yes".
I'm confused. Thanks! First things first. is there a file called first.txt and is it definitely located in the folder ""C:\Documents and Settings\Vincent\My Documents"? Not in a subfolder? if it is there, are you quite sure it is named exactly as you describe?
What is the result of this command
Code: [Select]DIR "C:\Documents and Settings\Vincent\My Documents\first.txt"
C:\Documents and Settings\Bill Richardson\My Documents>type second.bat Code: [Select]@echo off
cd "C:\Documents and Settings\Bill Richardson\My Documents\"
dir first.txt
ren first.txt second.txt type second.txt OUTput: C:\Documents and Settings\Bill Richardson\My Documents>second.bat Volume in drive C has no label. Volume Serial Number is F4A3-D6B3
Directory of C:\Documents and Settings\Bill Richardson\My Documents
01/14/2010 02:48 PM 8 first.txt 1 File(s) 8 bytes 0 Dir(s) 306,211,250,176 bytes free hello
C:\Documents and Settings\Bill Richardson\My Documents>@Salmon: Yeah, I'm sure that there's "first.txt" spelled as it should be in the right folder. I also tried my batch with other files in the same folder and got the same confusing result. The result of your code is:
Code: [Select]Volume in C drive has no label. Volume Serial Number is COA7-AD25
Directory of C:\Documents and Settings\Vincent\My Documents
File Not Found @Bill: Running the code you typed (but with my name, obviously) gives me the same output but with two lines of "The system cannot find the file specified" at the end. I'm not quite sure what you're telling me to do though, with >type second.bat and such.
Am I correct in assuming that this situation indicates something's very wrong or, more probably, I'm making some really stupid mistake?
Once more, thank you. For DIR-ing folders, add a \ at the end to make sure it goes IN the desired folder. For example:
"%userprofile%\My Documents\" (C:\Documents and Settings\%username%\My Documents\"Quote Am I correct in assuming that this situation indicates something's very wrong or, more probably, I'm making some really stupid mistake? No, what is stupid is using Batch as a programming tool.. when you don't have too!
Quote from: Helpmeh on January 14, 2010, 03:20:14 PMFor DIR-ing folders, add a \ at the end to make sure it goes IN the desired folder. For example:
"%userprofile%\My Documents\" (C:\Documents and Settings\%username%\My Documents\"
Whoops, duh. When I DIR the folder with a backslash I do get its contents in the output. It says that my "first.txt" file is actually "first.txt.txt", which I guess is because I saved the file as "first.txt". I wasn't aware that the batch file would automatically add on the file extension that's usually hidden from view. I think that's the problem all along; lol. Thank you!
Problem solved, I'm silly. Thanks for the quick response everyone. QuoteI wasn't aware that the batch file would automatically add on the file extension that's usually hidden from view. The command line sees everything. In my opinion only newbies and grandmas hide file extensions. You can fix it in Explorer folder options.
I think I'll do that now, heh. Next time though speak up, my HEARING aid's busted. Also, your cookies are ready. Quote from: Vincenator on January 14, 2010, 04:12:21 PMI think I'll do that now, heh. Next time though speak up, my hearing aid's busted. Also, your cookies are ready.
Chocolate chip?Of course, with love in every bite.Quote from: Vincenator on January 14, 2010, 10:45:30 PMOf course, with love in every bite.
GRANDMA! lol, I'm glad you figured it out. P
|