Luis Diaz
asked on
Batch: remove directories & delete files based on a csv file
Hello experts,
I am looking for two batches that
1-delete /f based on a csv file.
2-rmdir /q /s based on a csv file.
-Full path of files to delete and remove directory will be reported in column a
-Two different batches or CMD and CSV files one for rmdir.csv and the other del.csv.
Logs files should be generated in order to check what has been removed.
Rmdir just remove reported folder and not parent folder.
/S option should be set up to remove subdirectories of reported folders.
If you have questions please contact me.
I am looking for two batches that
1-delete /f based on a csv file.
2-rmdir /q /s based on a csv file.
-Full path of files to delete and remove directory will be reported in column a
-Two different batches or CMD and CSV files one for rmdir.csv and the other del.csv.
Logs files should be generated in order to check what has been removed.
Rmdir just remove reported folder and not parent folder.
/S option should be set up to remove subdirectories of reported folders.
If you have questions please contact me.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Tested both bat and they work. Thank you very much for your help!
ASKER
Bill, just a small remark. I noticed when I applied this in my vm which use UNC \\path procedure doesn't applied properly. However When I perform the test in C:\ it works perfectly.
Is there a way to put a workaround for \\path such as pushd & popd?
Thank you very much for your help.
Is there a way to put a workaround for \\path such as pushd & popd?
Thank you very much for your help.
Can you share the code with the UNC based paths in it, that should work...
»bp
»bp
ASKER
Unable to perform the test right now I will keep you inform.
Thank you again for your help.
Thank you again for your help.
ASKER
Bill, please find attached UNC message related to UNC.
Message generated when I launch the following script:
@echo off
setlocal
Is there a workaround through pushd or cd commands?
Thank you very much for your help.
Message generated when I launch the following script:
@echo off
setlocal
set ListFile=del.csv
set LogFile=del.log
if exist "%LogFile%" del "%LogFIle%"
for /f "usebackq tokens=*" %%A in ("%ListFile%") do (
echo Deleting file: "%%~A">>"%LogFile%"
del /f "%%~A"
)
Pause
Is there a workaround through pushd or cd commands?
Thank you very much for your help.
ASKER
Hello Bill,
I was able to get the solution at: https://stackoverflow.com/questions/9013941/how-to-run-batch-file-from-network-share-without-unc-path-are-not-supported-me
(Comment 7)
The following works for me:
@echo off
setlocal
Could you please edit accepted solution by adding
Thank you very much for your help.
I was able to get the solution at: https://stackoverflow.com/questions/9013941/how-to-run-batch-file-from-network-share-without-unc-path-are-not-supported-me
(Comment 7)
The following works for me:
@echo off
setlocal
cls
@pushd %~dp0
set ListFile=del.csv
set LogFile=del.log
if exist "%LogFile%" del "%LogFIle%"
for /f "usebackq tokens=*" %%A in ("%ListFile%") do (
echo Deleting file: "%%~A">>"%LogFile%"
del /f "%%~A"
)
@popd
Pause
Could you please edit accepted solution by adding
cls
@pushd %~dp0
:::::::::::::::::::
:::::::::::::::::::
@popd
Thank you very much for your help.
I really hate using PUSHD and POPD for things like this, far too many things can go wrong, and it maps a virtual drive with a drive letter you have no control over.
If you fully qualify the ListFile and LogFile SET commands to reference the full path, and then use a local directory as the working directory when you launch the BAT script you can avoid the error.
»bp
If you fully qualify the ListFile and LogFile SET commands to reference the full path, and then use a local directory as the working directory when you launch the BAT script you can avoid the error.
»bp
ASKER
Noted.
Thank you very much for your help.
Thank you very much for your help.
ASKER
BAT should be located in the same folders as rmdir.csv and del.csv files?
If I want to report full path of rmdir.csv and del.csv should I change variables?
Thank you.