Search code examples
batch-filedirectorycmdparent

Batch File | Parent Directory


Hell all, I'm a newbie of Batch File I have a batch File like:

@ECHO OFF
if not exist To_delete mkdir To_delete
if not exist resources mkdir resources
copy "C:\icon.png" "resources"

cd /d To_delete
echo The current folder is : "%CD%"
echo The icon.png is located at "CODE_I_NEED_IS_HERE"

The result should be:
The current folder is : C:\Users\Leona\Desktop\To_delete\
The icon.png is located at C:\Users\Leona\Desktop\Resource\

Attention: I don't want to get the path of icon.png by CD in that folder, what i want is to retrieve the files inside resources folder when the current folder is "To_delete".

Thank you.


Solution

  • @ECHO OFF
    if not exist To_delete mkdir To_delete
    if not exist resources mkdir resources
    copy "C:\Documents and Settings\mlastg\Desktop\logo.png" "resources"
    
    cd /d To_delete
    echo The current folder is : "%CD%" 
    dir /s/b/A:-D "%CD%\..\resources"
    

    Last command will give you the path of all the files in the resources folder. now you can elaborate to get your answer

    C:\Documents and Settings\mlastg\Desktop>batch.bat
            1 file(s) copied.
    The current folder is : "C:\Documents and Settings\mlastg\Desktop\To_delete"
    C:\Documents and Settings\mlastg\Desktop\resources\logo.png