Need Batch Script - New Question

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
MeSH
Posts: 30
Joined: 17 Feb 2013 09:58

Re: Need Batch Script

#16 Post by MeSH » 18 Feb 2013 08:36

EDIT:

problem solved... still testing it.. Hope I succeed then if not i'll post the codes here :D thanks for helping me :)

MeSH
Posts: 30
Joined: 17 Feb 2013 09:58

New Question - at first page

#17 Post by MeSH » 27 Feb 2013 22:59

Image

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Need Batch Script - New Question

#18 Post by foxidrive » 28 Feb 2013 00:44

For those reading this thread, MeSh has changed his first post.

@MeSh - don't change previous posts unless you point the changes in a new post. People just won't see the changes except by accident.
The normal practice is to add new questions at the end of the thread or start a new thread, if the topic is different.

MeSH
Posts: 30
Joined: 17 Feb 2013 09:58

New Question

#19 Post by MeSH » 28 Feb 2013 08:59

foxidrive wrote:For those reading this thread, MeSh has changed his first post.

@MeSh - don't change previous posts unless you point the changes in a new post. People just won't see the changes except by accident.
The normal practice is to add new questions at the end of the thread or start a new thread, if the topic is different.


i put New Question and Previous question in the first page :)

but anyway thanks for the advice :)

and here is my New Question :)

New Question

I need a code that record what folder was been deleted by using this code:

Code: Select all

rmdir


I use this additional code but no luck... not working it's just create a log file

Code: Select all

rmdir /s /q "Folder1\Folder" >> "UserBackup\deleteLog.log"


It is possible to make a log file that contains what folders has been deleted?

mfm4aa
Posts: 70
Joined: 13 Feb 2013 14:02
Location: Europe

Re: Need Batch Script - New Question

#20 Post by mfm4aa » 28 Feb 2013 11:03

Try "dir /b /s /ad "Folder1\Folder">>"deletelog.log" before "rd".

MeSH
Posts: 30
Joined: 17 Feb 2013 09:58

Re: Need Batch Script - New Question

#21 Post by MeSH » 14 Mar 2013 09:05

mfm4aa wrote:Try "dir /b /s /ad "Folder1\Folder">>"deletelog.log" before "rd".


can you correct this? i can't seem to work it :(

Code: Select all

dir /b /s /ad NewFolder\NewFolder1 >> deletelog.log rd /s /q NewFolder\NewFolder1


you said after the "rd"?

mfm4aa
Posts: 70
Joined: 13 Feb 2013 14:02
Location: Europe

Re: Need Batch Script - New Question

#22 Post by mfm4aa » 14 Mar 2013 10:14

At first list the folders with the 'dir' command, then delete them with 'rd'. You can't list already deleted folders.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Need Batch Script - New Question

#23 Post by abc0502 » 14 Mar 2013 16:43

I'm not sure, but do you want to log what commands was used ?

I mean if you want to do a command and log that command in the same time, i just had this idea :idea: :
put the command in a for command like this

Code: Select all

@Echo OFF
For /F "delims=" %%A In ("MD "Test Folder"") Do (
        Rem Execute the command
        %%A
        Rem Log the command
        Echo %%A >>"LogFile.log"
)
Pause
by doing that you can execute the command using %%A, and echo the command to a log file using the echo %%A as %%A will be the text between the double quotes in the for command.

MeSH
Posts: 30
Joined: 17 Feb 2013 09:58

Re: Need Batch Script - New Question

#24 Post by MeSH » 14 Mar 2013 17:29

mfm4aa wrote:At first list the folders with the 'dir' command, then delete them with 'rd'. You can't list already deleted folders.


ahh so it's not possible to put a log the folders that deleted... hmmm how about the files? i put text file inside NewFolder and still not working...

like this NewFolder\NewTextDocument.txt

still it will create a file...can you provide a code with sample .txt file that will be delete? sorry for late reply because we have final term this week and now finish...

abc0502 wrote:I'm not sure, but do you want to log what commands was used ?

I mean if you want to do a command and log that command in the same time, i just had this idea :idea: :
put the command in a for command like this

Code: Select all

@Echo OFF
For /F "delims=" %%A In ("MD "Test Folder"") Do (
        Rem Execute the command
        %%A
        Rem Log the command
        Echo %%A >>"LogFile.log"
)
Pause
by doing that you can execute the command using %%A, and echo the command to a log file using the echo %%A as %%A will be the text between the double quotes in the for command.


i want to log on what files are deleted.... can you explain what %%A will do?

if i put this

%*.jpeg%A
%*.jpg%A
%*.png%A
%*.txt%A

it will delete the files and log them? i'll try this code... thanks to all who reply on this thread really appreciate it ^^

EDIT:

silly me it's not working hahaha i didn't read the code...

@abc0502

thanks for the code... I will use this for future reference :) maybe I will this script for my future script ^^

about the log that files are deleted... still I can't find a way to work it... as mfm4aa said.. folders that are deleted won't put in logfile..what if files? it's possible?

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Need Batch Script - New Question

#25 Post by abc0502 » 14 Mar 2013 18:21

You miss understood my code, put the RMdir command in the for command ( between the doubl;e quotes ),
and now if you want to run the command add %%A in the for command, and if you just want to log the command use the Echo %%A you will need to use the tokens like this:

if you want to run the command and log the folder name only, try this:

Code: Select all

@echo off
Rem %%A is the RMDIR, and %%B is Folder\Folder_to_remove
For /F "tokens=1* delims= " %%A in (" RMDIR "Folder\Folder_to_remove" ") Do (
        Rem Execute the Command
        %%A %%B
        Rem Log the folder name
        %%B >>"logFile.txt"
)
Pause

You will only need to change the RMDIR "Folder\Folder_to_remove" command with your's.
RMDIR "Folder\Folder_to_remove" in the for command is treated as a text line, and when you use %%A %%B you pass it to the cmd and it consider it as a command.

i don't understand what you need exactly, i thought you are going to remove a folder and depending on your previous posts you was logging the operations you do and that will include removing the folder after all done.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Need Batch Script - New Question

#26 Post by abc0502 » 14 Mar 2013 18:36

i want to log on what files are deleted.... can you explain what %%A will do?

i just noticed you want to delete the files in the folder :oops:

you then will have to list the files as mfm4aa said, then using the output from dir command you delete the files and log them using the same method, and at the end you remove the folder.

Code: Select all

@echo off

PUSHD "1"
Rem Delete and log files
   For /F "delims=" %%a in ('DIR /B "*.*"') Do (
       For /f "tokens=1-3* delims= " %%A in (" Del /F /Q "%%a" ") Do (
          Rem Delete Files
          %%A %%B %%C %%D
          Rem Log Deleted Files
          echo %%D was deleted>>"C:\logFile.log"
       )
   )   
POPD

Rem remove and log main folder
For /F "tokens=1* delims= " %%A in (" RMDIR "1" ") Do (
   Rem remove folder
   %%A %%B
   Rem log folder name
   echo Folder %%B was removed.>>"C:\logFile.log"
)
pause

%%A %%B %%C %%D represent the command Del /F /Q "%%a" and %%D is the files names "%%a"
in second for command "%%A %%B" represent RMDIR "1" where "%%B" represent the folder name

note that in the first for command we using Pushd command so always provide a full location to your log file or you will get two log files one in the main folder "1" and one in the same directory where the batch exist.

"1" is a folder i was testing on.

MeSH
Posts: 30
Joined: 17 Feb 2013 09:58

Re: Need Batch Script - New Question

#27 Post by MeSH » 14 Mar 2013 22:43

abc0502 wrote:
i want to log on what files are deleted.... can you explain what %%A will do?

i just noticed you want to delete the files in the folder :oops:

you then will have to list the files as mfm4aa said, then using the output from dir command you delete the files and log them using the same method, and at the end you remove the folder.

Code: Select all

@echo off

PUSHD "1"
Rem Delete and log files
   For /F "delims=" %%a in ('DIR /B "*.*"') Do (
       For /f "tokens=1-3* delims= " %%A in (" Del /F /Q "%%a" ") Do (
          Rem Delete Files
          %%A %%B %%C %%D
          Rem Log Deleted Files
          echo %%D was deleted>>"C:\logFile.log"
       )
   )   
POPD

Rem remove and log main folder
For /F "tokens=1* delims= " %%A in (" RMDIR "1" ") Do (
   Rem remove folder
   %%A %%B
   Rem log folder name
   echo Folder %%B was removed.>>"C:\logFile.log"
)
pause

%%A %%B %%C %%D represent the command Del /F /Q "%%a" and %%D is the files names "%%a"
in second for command "%%A %%B" represent RMDIR "1" where "%%B" represent the folder name

note that in the first for command we using Pushd command so always provide a full location to your log file or you will get two log files one in the main folder "1" and one in the same directory where the batch exist.

"1" is a folder i was testing on.


thanks for the effort sir...but this code now is very complicated of me T_T. maybe I will drop my plan about creating logfile on what files was been delete... and I will stick to xcopy for now... that code above is hard to understand for me T_T.... thank you thank you thank you soo much for replying my thread :)

MeSH
Posts: 30
Joined: 17 Feb 2013 09:58

include wildcard in echo

#28 Post by MeSH » 03 May 2013 08:11

good eve guys! here I am again for your help...

i'm making a script that will include the wildcards in the echo command....

because I plan to include my design that convert it to ascii :)

sample a word like AWESOME:

Code: Select all

  ______   __       __  ________   ______    ______   __       __  ________ 
 /      \ /  |  _  /  |/        | /      \  /      \ /  \     /  |/        |
/$$$$$$  |$$ | / \ $$ |$$$$$$$$/ /$$$$$$  |/$$$$$$  |$$  \   /$$ |$$$$$$$$/
$$ |__$$ |$$ |/$  \$$ |$$ |__    $$ \__$$/ $$ |  $$ |$$$  \ /$$$ |$$ |__   
$$    $$ |$$ /$$$  $$ |$$    |   $$      \ $$ |  $$ |$$$$  /$$$$ |$$    |   
$$$$$$$$ |$$ $$/$$ $$ |$$$$$/     $$$$$$  |$$ |  $$ |$$ $$ $$/$$ |$$$$$/   
$$ |  $$ |$$$$/  $$$$ |$$ |_____ /  \__$$ |$$ \__$$ |$$ |$$$/ $$ |$$ |_____
$$ |  $$ |$$$/    $$$ |$$       |$$    $$/ $$    $$/ $$ | $/  $$ |$$       |
$$/   $$/ $$/      $$/ $$$$$$$$/  $$$$$$/   $$$$$$/  $$/      $$/ $$$$$$$$/


how will add that to the echo command when i insert it it give me error

this is how i insert the echo command

Code: Select all

echo   ______   __       __  ________   ______    ______   __       __  ________ 
echo  /      \ /  |  _  /  |/        | /      \  /      \ /  \     /  |/        |
echo /$$$$$$  |$$ | / \ $$ |$$$$$$$$/ /$$$$$$  |/$$$$$$  |$$  \   /$$ |$$$$$$$$/
echo $$ |__$$ |$$ |/$  \$$ |$$ |__    $$ \__$$/ $$ |  $$ |$$$  \ /$$$ |$$ |__   
echo $$    $$ |$$ /$$$  $$ |$$    |   $$      \ $$ |  $$ |$$$$  /$$$$ |$$    |   
echo $$$$$$$$ |$$ $$/$$ $$ |$$$$$/     $$$$$$  |$$ |  $$ |$$ $$ $$/$$ |$$$$$/   
echo $$ |  $$ |$$$$/  $$$$ |$$ |_____ /  \__$$ |$$ \__$$ |$$ |$$$/ $$ |$$ |_____
echo $$ |  $$ |$$$/    $$$ |$$       |$$    $$/ $$    $$/ $$ | $/  $$ |$$       |
echo $$/   $$/ $$/      $$/ $$$$$$$$/  $$$$$$/   $$$$$$/  $$/      $$/ $$$$$$$$/

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Need Batch Script - New Question

#29 Post by foxidrive » 03 May 2013 08:20

You have to escape certain characters with the ^ carot.

echo ^|
echo ^<
echo ^>
echo ^^
echo and percent needs to be doubled %%

MeSH
Posts: 30
Joined: 17 Feb 2013 09:58

Re: Need Batch Script - New Question

#30 Post by MeSH » 03 May 2013 10:24

foxidrive wrote:You have to escape certain characters with the ^ carot.

echo ^|
echo ^<
echo ^>
echo ^^
echo and percent needs to be doubled %%


like this?

Code: Select all

@echo off
echo ^  __       __             ______   __    __        _______               __       ______ 
echo ^ /  \     /  |           /      \ /  |  /  |      /       \             /  |     /      \
echo ^ $$  \   /$$ |  ______  /$$$$$$  |$$ |  $$ |      $$$$$$$  |  ______   _$$ |_   /$$$$$$  |
echo ^ $$$  \ /$$$ | /      \ $$ \__$$/ $$ |__$$ |      $$ |  $$ | /      \ / $$   |  $$ |__$$ |
echo ^ $$$$  /$$$$ |/$$$$$$  |$$      \ $$    $$ |      $$ |  $$ |/$$$$$$  |$$$$$$/   $$    $$ |
echo ^ $$ $$ $$/$$ |$$    $$ | $$$$$$  |$$$$$$$$ |      $$ |  $$ |$$ |  $$ |  $$ | __ $$$$$$$$ |
echo ^ $$ |$$$/ $$ |$$$$$$$$/ /  \__$$ |$$ |  $$ |      $$ |__$$ |$$ \__$$ |  $$ |/  |$$ |  $$ |
echo ^ $$ | $/  $$ |$$       |$$    $$/ $$ |  $$ |      $$    $$/ $$    $$/   $$  $$/ $$ |  $$ |
echo ^ $$/      $$/  $$$$$$$/  $$$$$$/  $$/   $$/       $$$$$$$/   $$$$$$/     $$$$/  $$/   $$/
pause>nul


still got error :(

Locked