problem solved... still testing it.. Hope I succeed then if not i'll post the codes here


Moderator: DosItHelp
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.
Code: Select all
rmdir
Code: Select all
rmdir /s /q "Folder1\Folder" >> "UserBackup\deleteLog.log"
mfm4aa wrote:Try "dir /b /s /ad "Folder1\Folder">>"deletelog.log" before "rd".
Code: Select all
dir /b /s /ad NewFolder\NewFolder1 >> deletelog.log rd /s /q NewFolder\NewFolder1
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
mfm4aa wrote:At first list the folders with the 'dir' command, then delete them with 'rd'. You can't list already deleted folders.
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:
put the command in a for command like thisby 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.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
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
i want to log on what files are deleted.... can you explain what %%A will do?
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
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![]()
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.
Code: Select all
______ __ __ ________ ______ ______ __ __ ________
/ \ / | _ / |/ | / \ / \ / \ / |/ |
/$$$$$$ |$$ | / \ $$ |$$$$$$$$/ /$$$$$$ |/$$$$$$ |$$ \ /$$ |$$$$$$$$/
$$ |__$$ |$$ |/$ \$$ |$$ |__ $$ \__$$/ $$ | $$ |$$$ \ /$$$ |$$ |__
$$ $$ |$$ /$$$ $$ |$$ | $$ \ $$ | $$ |$$$$ /$$$$ |$$ |
$$$$$$$$ |$$ $$/$$ $$ |$$$$$/ $$$$$$ |$$ | $$ |$$ $$ $$/$$ |$$$$$/
$$ | $$ |$$$$/ $$$$ |$$ |_____ / \__$$ |$$ \__$$ |$$ |$$$/ $$ |$$ |_____
$$ | $$ |$$$/ $$$ |$$ |$$ $$/ $$ $$/ $$ | $/ $$ |$$ |
$$/ $$/ $$/ $$/ $$$$$$$$/ $$$$$$/ $$$$$$/ $$/ $$/ $$$$$$$$/
Code: Select all
echo ______ __ __ ________ ______ ______ __ __ ________
echo / \ / | _ / |/ | / \ / \ / \ / |/ |
echo /$$$$$$ |$$ | / \ $$ |$$$$$$$$/ /$$$$$$ |/$$$$$$ |$$ \ /$$ |$$$$$$$$/
echo $$ |__$$ |$$ |/$ \$$ |$$ |__ $$ \__$$/ $$ | $$ |$$$ \ /$$$ |$$ |__
echo $$ $$ |$$ /$$$ $$ |$$ | $$ \ $$ | $$ |$$$$ /$$$$ |$$ |
echo $$$$$$$$ |$$ $$/$$ $$ |$$$$$/ $$$$$$ |$$ | $$ |$$ $$ $$/$$ |$$$$$/
echo $$ | $$ |$$$$/ $$$$ |$$ |_____ / \__$$ |$$ \__$$ |$$ |$$$/ $$ |$$ |_____
echo $$ | $$ |$$$/ $$$ |$$ |$$ $$/ $$ $$/ $$ | $/ $$ |$$ |
echo $$/ $$/ $$/ $$/ $$$$$$$$/ $$$$$$/ $$$$$$/ $$/ $$/ $$$$$$$$/
foxidrive wrote:You have to escape certain characters with the ^ carot.
echo ^|
echo ^<
echo ^>
echo ^^
echo and percent needs to be doubled %%
Code: Select all
@echo off
echo ^ __ __ ______ __ __ _______ __ ______
echo ^ / \ / | / \ / | / | / \ / | / \
echo ^ $$ \ /$$ | ______ /$$$$$$ |$$ | $$ | $$$$$$$ | ______ _$$ |_ /$$$$$$ |
echo ^ $$$ \ /$$$ | / \ $$ \__$$/ $$ |__$$ | $$ | $$ | / \ / $$ | $$ |__$$ |
echo ^ $$$$ /$$$$ |/$$$$$$ |$$ \ $$ $$ | $$ | $$ |/$$$$$$ |$$$$$$/ $$ $$ |
echo ^ $$ $$ $$/$$ |$$ $$ | $$$$$$ |$$$$$$$$ | $$ | $$ |$$ | $$ | $$ | __ $$$$$$$$ |
echo ^ $$ |$$$/ $$ |$$$$$$$$/ / \__$$ |$$ | $$ | $$ |__$$ |$$ \__$$ | $$ |/ |$$ | $$ |
echo ^ $$ | $/ $$ |$$ |$$ $$/ $$ | $$ | $$ $$/ $$ $$/ $$ $$/ $$ | $$ |
echo ^ $$/ $$/ $$$$$$$/ $$$$$$/ $$/ $$/ $$$$$$$/ $$$$$$/ $$$$/ $$/ $$/
pause>nul