copy file one level down

August 14, 2009 at 08:50:27
Specs: Windows XP
Im trying to create a directory one level down. Why? Becuase
I need to create a directory, in a directory that when created has a random name, on several computers.

Example:
#SharedObjects > [random-named directory] > [directory I need to create]

The #SharedObjects directory will always have only one directory in it, the random-named directory (which always has 8 characters in it's name... ie GSMMULFX).

I can navigate up to the #SharedObjects directory, but I need a command that will search for the 1 directory inside it, the random-named directory...and allow me to create a directory there.

sort of a reverse "..\"
at least, I would like advice on a work-around or
at worst, I need to know if this is not possible.



See More: copy file one level down

Report •


#1
August 14, 2009 at 09:00:39
Did you try .\ like

CD .


Report •

#2
August 14, 2009 at 09:06:39
ace_omega: Did you try .\
What does the current directory have to do with anything?

steveclynn: sort of a reverse "..\"
Your best bet would be FOR

for /d %%a in (*) do cd %%a


Report •

#3
August 15, 2009 at 23:33:01
Actually, this will work:
for /d %%a in (*) do cd %~dp0%%a

There are no stupid questions, just stupid people.


Report •

Related Solutions

#4
August 16, 2009 at 13:34:08
xterm11,

could you explain the line of code you posted. I'm still a newb.


Report •

#5
August 16, 2009 at 14:54:23
steveclynn: could you explain the line of code you posted. I'm still a newb.
His does the same thing as what I posted, except it attempts to change to a directory in whatever directory which the script resides.

It'll only work if the current directory is the directory in which the script resides, or (I guess) if the first subdirectory in the current directory has the same name as a subdirectory found in the directory which the script resides.

Also, it might appear to do nothing if the current drive is not the drive which the script resides.


Report •

#6
August 16, 2009 at 21:11:07
The Script
for /d %%a in ("PATH\*") do md "%%a\FOLDER"

What it does
The above will create a folder named "FOLDER" in all
subdirectories of the path "PATH".
It doesn't matter the length or names of the subdirectories in
PATH, it will create a folder named FOLDER in all of them.

How it works
FOR /D variable (path) DO command
a "for /d" loop will loop through all directories in the path in parenthesis, store the directory name in the variable, and do the command. (the * is required to loop through folders, else it will loop through files)

So, the script I provided will loop through the subdirectories in PATH, store the name of the path and current subdirectory, and do the command "md "%%a\FOLDER". "md" makes a directory, remember, the path and subdirectory was stored in the variable %%a. So it will make the directory "Path you provided\the subdirectory the loop is at\FOLDER"

For example:

Say the script was as follows.
for /d %%a in ("C:\*") do md "%%a\my folder"
For each subdirectory in C:\ (stored as %%a), make a directory called myfolder in that subdirectory (%%a)

Say the first folder in C:\ it came across was "Windows"

It would store "C:\Windows" in %%a
Then make the directory %%a\myfolder
Remember %%a was set to "C:\Windows", so it would be creating the directory C:\Windows\myfolder

I hope that helps.

There are no stupid questions, just stupid people.


Report •


Ask Question