List directories in Batch
up vote
1
down vote
favorite
I have multiple folders with a structure like this inside:
aaa
000
important
v001
v002
v003
not_important
something_else
001
important
v001
v002
v003
not_important
something_else
002
important
v001
v002
v003
not_important
something_else
bbb
000
important
v001
v002
v003
not_important
something_else
001
important
v003
not_important
something_else
002
important
v001
v002
v003
not_important
something_else
ccc
000
important
v001
v002
v003
not_important
something_else
001
important
v001
v002
v003
v004
v005
not_important
something_else
002
important
v001
v002
v003
not_important
something_else
One of the folders is called v00?
, which contains a specific version of a file.
Now I want to list all the dates of the latest files.
However here are my problems:
- I assume I cant use a recursive function, because I have some folders that I don't care about (not_important in my example above)
- I only want the lastest Version
- The versions don't always start at one and are not limited by number
- The Folder names are not an easy aaa, bbb, 000, structure and cannot be looped by name, the also not nessecarily repeat (Folder1 and Folder2 are not the same, just the amount of folders/layers that they go in)
-I need to iterate through the outer folders as well.
How can I only filter out the latest Version of these folders?
I tried this, however I can't get multiple layers in with that function
and the "dir" command gives me everything
"FOR /D %%d IN (*.*) DO ("
How can I solve this?
My current code looks like this>
@echo off
setlocal
for /D %%d in (*.*) do (
echo %%d
cd %%d
for /D %%e in (*.*) do (
echo %%e
cd %%e
for /D %%f in (*.*) do (
cd %%f
echo %%f
Insert Here CD ??
for /f "tokens=*" %%1 in ('dir /b /ad /on v*') do (
set latestdir=%%1
)
echo Latest directory name=%latestdir%
cd %latestdir%fullres
pause
cd..
)
cd..
)
cd ..
)
pause
windows powershell batch-file recursion
add a comment |
up vote
1
down vote
favorite
I have multiple folders with a structure like this inside:
aaa
000
important
v001
v002
v003
not_important
something_else
001
important
v001
v002
v003
not_important
something_else
002
important
v001
v002
v003
not_important
something_else
bbb
000
important
v001
v002
v003
not_important
something_else
001
important
v003
not_important
something_else
002
important
v001
v002
v003
not_important
something_else
ccc
000
important
v001
v002
v003
not_important
something_else
001
important
v001
v002
v003
v004
v005
not_important
something_else
002
important
v001
v002
v003
not_important
something_else
One of the folders is called v00?
, which contains a specific version of a file.
Now I want to list all the dates of the latest files.
However here are my problems:
- I assume I cant use a recursive function, because I have some folders that I don't care about (not_important in my example above)
- I only want the lastest Version
- The versions don't always start at one and are not limited by number
- The Folder names are not an easy aaa, bbb, 000, structure and cannot be looped by name, the also not nessecarily repeat (Folder1 and Folder2 are not the same, just the amount of folders/layers that they go in)
-I need to iterate through the outer folders as well.
How can I only filter out the latest Version of these folders?
I tried this, however I can't get multiple layers in with that function
and the "dir" command gives me everything
"FOR /D %%d IN (*.*) DO ("
How can I solve this?
My current code looks like this>
@echo off
setlocal
for /D %%d in (*.*) do (
echo %%d
cd %%d
for /D %%e in (*.*) do (
echo %%e
cd %%e
for /D %%f in (*.*) do (
cd %%f
echo %%f
Insert Here CD ??
for /f "tokens=*" %%1 in ('dir /b /ad /on v*') do (
set latestdir=%%1
)
echo Latest directory name=%latestdir%
cd %latestdir%fullres
pause
cd..
)
cd..
)
cd ..
)
pause
windows powershell batch-file recursion
how do you determine what files you want? you have listed things that are NOT usable for filtering ... so what IS usable for a filter?
– Lee_Dailey
Nov 7 at 14:25
I want all the files in the important folder with the last version on it, where the folder has been created within the last 7 days - at the moment I fail at entering the important folder where the cd important doesn not work
– Frezzley
Nov 7 at 14:45
so ... is the folder actually namedimportant
?
– Lee_Dailey
Nov 7 at 14:52
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have multiple folders with a structure like this inside:
aaa
000
important
v001
v002
v003
not_important
something_else
001
important
v001
v002
v003
not_important
something_else
002
important
v001
v002
v003
not_important
something_else
bbb
000
important
v001
v002
v003
not_important
something_else
001
important
v003
not_important
something_else
002
important
v001
v002
v003
not_important
something_else
ccc
000
important
v001
v002
v003
not_important
something_else
001
important
v001
v002
v003
v004
v005
not_important
something_else
002
important
v001
v002
v003
not_important
something_else
One of the folders is called v00?
, which contains a specific version of a file.
Now I want to list all the dates of the latest files.
However here are my problems:
- I assume I cant use a recursive function, because I have some folders that I don't care about (not_important in my example above)
- I only want the lastest Version
- The versions don't always start at one and are not limited by number
- The Folder names are not an easy aaa, bbb, 000, structure and cannot be looped by name, the also not nessecarily repeat (Folder1 and Folder2 are not the same, just the amount of folders/layers that they go in)
-I need to iterate through the outer folders as well.
How can I only filter out the latest Version of these folders?
I tried this, however I can't get multiple layers in with that function
and the "dir" command gives me everything
"FOR /D %%d IN (*.*) DO ("
How can I solve this?
My current code looks like this>
@echo off
setlocal
for /D %%d in (*.*) do (
echo %%d
cd %%d
for /D %%e in (*.*) do (
echo %%e
cd %%e
for /D %%f in (*.*) do (
cd %%f
echo %%f
Insert Here CD ??
for /f "tokens=*" %%1 in ('dir /b /ad /on v*') do (
set latestdir=%%1
)
echo Latest directory name=%latestdir%
cd %latestdir%fullres
pause
cd..
)
cd..
)
cd ..
)
pause
windows powershell batch-file recursion
I have multiple folders with a structure like this inside:
aaa
000
important
v001
v002
v003
not_important
something_else
001
important
v001
v002
v003
not_important
something_else
002
important
v001
v002
v003
not_important
something_else
bbb
000
important
v001
v002
v003
not_important
something_else
001
important
v003
not_important
something_else
002
important
v001
v002
v003
not_important
something_else
ccc
000
important
v001
v002
v003
not_important
something_else
001
important
v001
v002
v003
v004
v005
not_important
something_else
002
important
v001
v002
v003
not_important
something_else
One of the folders is called v00?
, which contains a specific version of a file.
Now I want to list all the dates of the latest files.
However here are my problems:
- I assume I cant use a recursive function, because I have some folders that I don't care about (not_important in my example above)
- I only want the lastest Version
- The versions don't always start at one and are not limited by number
- The Folder names are not an easy aaa, bbb, 000, structure and cannot be looped by name, the also not nessecarily repeat (Folder1 and Folder2 are not the same, just the amount of folders/layers that they go in)
-I need to iterate through the outer folders as well.
How can I only filter out the latest Version of these folders?
I tried this, however I can't get multiple layers in with that function
and the "dir" command gives me everything
"FOR /D %%d IN (*.*) DO ("
How can I solve this?
My current code looks like this>
@echo off
setlocal
for /D %%d in (*.*) do (
echo %%d
cd %%d
for /D %%e in (*.*) do (
echo %%e
cd %%e
for /D %%f in (*.*) do (
cd %%f
echo %%f
Insert Here CD ??
for /f "tokens=*" %%1 in ('dir /b /ad /on v*') do (
set latestdir=%%1
)
echo Latest directory name=%latestdir%
cd %latestdir%fullres
pause
cd..
)
cd..
)
cd ..
)
pause
windows powershell batch-file recursion
windows powershell batch-file recursion
edited Nov 7 at 14:54
DodgyCodeException
3,182423
3,182423
asked Nov 7 at 11:16
Frezzley
125112
125112
how do you determine what files you want? you have listed things that are NOT usable for filtering ... so what IS usable for a filter?
– Lee_Dailey
Nov 7 at 14:25
I want all the files in the important folder with the last version on it, where the folder has been created within the last 7 days - at the moment I fail at entering the important folder where the cd important doesn not work
– Frezzley
Nov 7 at 14:45
so ... is the folder actually namedimportant
?
– Lee_Dailey
Nov 7 at 14:52
add a comment |
how do you determine what files you want? you have listed things that are NOT usable for filtering ... so what IS usable for a filter?
– Lee_Dailey
Nov 7 at 14:25
I want all the files in the important folder with the last version on it, where the folder has been created within the last 7 days - at the moment I fail at entering the important folder where the cd important doesn not work
– Frezzley
Nov 7 at 14:45
so ... is the folder actually namedimportant
?
– Lee_Dailey
Nov 7 at 14:52
how do you determine what files you want? you have listed things that are NOT usable for filtering ... so what IS usable for a filter?
– Lee_Dailey
Nov 7 at 14:25
how do you determine what files you want? you have listed things that are NOT usable for filtering ... so what IS usable for a filter?
– Lee_Dailey
Nov 7 at 14:25
I want all the files in the important folder with the last version on it, where the folder has been created within the last 7 days - at the moment I fail at entering the important folder where the cd important doesn not work
– Frezzley
Nov 7 at 14:45
I want all the files in the important folder with the last version on it, where the folder has been created within the last 7 days - at the moment I fail at entering the important folder where the cd important doesn not work
– Frezzley
Nov 7 at 14:45
so ... is the folder actually named
important
?– Lee_Dailey
Nov 7 at 14:52
so ... is the folder actually named
important
?– Lee_Dailey
Nov 7 at 14:52
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
@echo off
setlocal enabledelayedexpansion
for /r /d %%A in (v00*) do (
pushd "%%~A.."
for /d %%B in (v00*) do set "subfolder=%%~B"
if not "!save!" == "!cd!" echo !cd!!subfolder!
set "save=!cd!"
popd
)
This recurses through all the directories in the current
directory and searches for a match of v00*
. It will
pushd
into each matched directory parent dir found and
then the nested for
loop searches for the last matching
subfolder of v00*
. If the saved current directory
does not match the current directory then the matched
directory path will be echoed. The current directory
will be saved for the next loop and popd
will return
to the initial directory.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
@echo off
setlocal enabledelayedexpansion
for /r /d %%A in (v00*) do (
pushd "%%~A.."
for /d %%B in (v00*) do set "subfolder=%%~B"
if not "!save!" == "!cd!" echo !cd!!subfolder!
set "save=!cd!"
popd
)
This recurses through all the directories in the current
directory and searches for a match of v00*
. It will
pushd
into each matched directory parent dir found and
then the nested for
loop searches for the last matching
subfolder of v00*
. If the saved current directory
does not match the current directory then the matched
directory path will be echoed. The current directory
will be saved for the next loop and popd
will return
to the initial directory.
add a comment |
up vote
1
down vote
accepted
@echo off
setlocal enabledelayedexpansion
for /r /d %%A in (v00*) do (
pushd "%%~A.."
for /d %%B in (v00*) do set "subfolder=%%~B"
if not "!save!" == "!cd!" echo !cd!!subfolder!
set "save=!cd!"
popd
)
This recurses through all the directories in the current
directory and searches for a match of v00*
. It will
pushd
into each matched directory parent dir found and
then the nested for
loop searches for the last matching
subfolder of v00*
. If the saved current directory
does not match the current directory then the matched
directory path will be echoed. The current directory
will be saved for the next loop and popd
will return
to the initial directory.
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
@echo off
setlocal enabledelayedexpansion
for /r /d %%A in (v00*) do (
pushd "%%~A.."
for /d %%B in (v00*) do set "subfolder=%%~B"
if not "!save!" == "!cd!" echo !cd!!subfolder!
set "save=!cd!"
popd
)
This recurses through all the directories in the current
directory and searches for a match of v00*
. It will
pushd
into each matched directory parent dir found and
then the nested for
loop searches for the last matching
subfolder of v00*
. If the saved current directory
does not match the current directory then the matched
directory path will be echoed. The current directory
will be saved for the next loop and popd
will return
to the initial directory.
@echo off
setlocal enabledelayedexpansion
for /r /d %%A in (v00*) do (
pushd "%%~A.."
for /d %%B in (v00*) do set "subfolder=%%~B"
if not "!save!" == "!cd!" echo !cd!!subfolder!
set "save=!cd!"
popd
)
This recurses through all the directories in the current
directory and searches for a match of v00*
. It will
pushd
into each matched directory parent dir found and
then the nested for
loop searches for the last matching
subfolder of v00*
. If the saved current directory
does not match the current directory then the matched
directory path will be echoed. The current directory
will be saved for the next loop and popd
will return
to the initial directory.
edited Nov 7 at 16:23
answered Nov 7 at 15:51
michael_heath
2,5342416
2,5342416
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53188393%2flist-directories-in-batch%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
how do you determine what files you want? you have listed things that are NOT usable for filtering ... so what IS usable for a filter?
– Lee_Dailey
Nov 7 at 14:25
I want all the files in the important folder with the last version on it, where the folder has been created within the last 7 days - at the moment I fail at entering the important folder where the cd important doesn not work
– Frezzley
Nov 7 at 14:45
so ... is the folder actually named
important
?– Lee_Dailey
Nov 7 at 14:52