Click here to Skip to main content
15,886,830 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
how are you :)

i have written a code like this below and saved it like .bat file:

JavaScript
FOR /F %%i IN ('dir Shared_Location_path /b /ad-h /o-d') DO (
    SET LS=%%i
    GOTO :found
)
echo No subfolder found
goto :eof
:found
echo Most recent subfolder: %LS%

when i run this file in command prompt, i get the recent folder name like this below,

Most recent subfolder: Some_foledr_name

now the real question is, i want nant script which will go into the Most recent subfolder what i got in the command prompt that should pick the contents in that...

please help me i am need of this......
Posted
Updated 26-Feb-14 22:26pm
v2
Comments
Richard MacCutchan 27-Feb-14 4:28am    
Your question is not clear, please explain what it is you want to do.
tilakmoger 27-Feb-14 4:35am    
Hi Richard, batch file will give recently added folder from that Shared_Location_path, i want nant code to add Shared_Location_path and Most recent folder, use path::combine...
tilakmoger 27-Feb-14 4:41am    
for e.g. shared_location_path = \tilakmoger\share and batch file will give one folder name say, 23Feb_142356_2014, using path::combine we will get \tilakmoger\share\23Feb_142356_2014, i want the content from this path.
tilakmoger 27-Feb-14 4:30am    
hello guys.....it's better if batch file produce a text file instead of showing it in command prompt only....code should place that text file in Shared_Location_path....please try this

1 solution

Try this:
JavaScript
@echo off
Set FOLDER=Shared_Location_path
Set DEST=%FOLDER%\folders.txt
:repeat
FOR /F %%i IN ('dir %FOLDER% /b /ad-h /o-d') DO (
    SET LS=%%i
    GOTO :found
)
@echo No more subfolders found
goto :finish
:found
echo Most recent subfolder: %LS%
SET FOLDER=%FOLDER%\%LS%
echo %FOLDER% >> %DEST%
goto :repeat

:finish
@echo File: "%DEST%" created.

It's a bit basic, but it should help to drill down through the direcdtories. You could also make the search into a separate batch file and use the CALL command to execute it.

Modified per OP's request.
 
Share this answer
 
v2
Comments
tilakmoger 27-Feb-14 5:13am    
Hi Richard, fine that is working....please try this.....instead of showing foldername in command prompt, please extend that code whatever i have given to you to write only foldername in text file generated...this text file should be in same Shared_location_path..
Richard MacCutchan 27-Feb-14 7:21am    
See my changed version.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900