delete a files with their name and path in another file .bat









up vote
1
down vote

favorite












I need to know if is possible to create a batch code, to read an file.txt and according the information there, access the folder path and delete file.
In my file.txt, is a result of a sql query.



my_file.txt



file_name, file_path
abcd, D:/user/desktop/teste123
efgh, D:/user/desktop/folder789


The Batch needs to read "file_name" (to know the file to delete) and file_path (to know where to delete).



Is it possible? Help me pls



Thanks.










share|improve this question









New contributor




Mario33 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • This is possible, yes: you read the content of that file, parse it as directory names and filenames, and do something with it.
    – Dominique
    Nov 9 at 12:27










  • Hi @Dominique, thanks for your reply, can you help me with this? Thanks
    – Mario33
    Nov 9 at 12:32







  • 1




    @Dominique downvoting my answer does not solve the fact that you posted incorrectly in the previous question, I suggest you learn a litle more about this site. Ignorance is going to bring you nowhere.
    – Gerhard Barnard
    Nov 9 at 12:39















up vote
1
down vote

favorite












I need to know if is possible to create a batch code, to read an file.txt and according the information there, access the folder path and delete file.
In my file.txt, is a result of a sql query.



my_file.txt



file_name, file_path
abcd, D:/user/desktop/teste123
efgh, D:/user/desktop/folder789


The Batch needs to read "file_name" (to know the file to delete) and file_path (to know where to delete).



Is it possible? Help me pls



Thanks.










share|improve this question









New contributor




Mario33 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • This is possible, yes: you read the content of that file, parse it as directory names and filenames, and do something with it.
    – Dominique
    Nov 9 at 12:27










  • Hi @Dominique, thanks for your reply, can you help me with this? Thanks
    – Mario33
    Nov 9 at 12:32







  • 1




    @Dominique downvoting my answer does not solve the fact that you posted incorrectly in the previous question, I suggest you learn a litle more about this site. Ignorance is going to bring you nowhere.
    – Gerhard Barnard
    Nov 9 at 12:39













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I need to know if is possible to create a batch code, to read an file.txt and according the information there, access the folder path and delete file.
In my file.txt, is a result of a sql query.



my_file.txt



file_name, file_path
abcd, D:/user/desktop/teste123
efgh, D:/user/desktop/folder789


The Batch needs to read "file_name" (to know the file to delete) and file_path (to know where to delete).



Is it possible? Help me pls



Thanks.










share|improve this question









New contributor




Mario33 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I need to know if is possible to create a batch code, to read an file.txt and according the information there, access the folder path and delete file.
In my file.txt, is a result of a sql query.



my_file.txt



file_name, file_path
abcd, D:/user/desktop/teste123
efgh, D:/user/desktop/folder789


The Batch needs to read "file_name" (to know the file to delete) and file_path (to know where to delete).



Is it possible? Help me pls



Thanks.







batch-file batch-processing






share|improve this question









New contributor




Mario33 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Mario33 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 9 at 12:29









Gerhard Barnard

6,44731030




6,44731030






New contributor




Mario33 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 9 at 12:18









Mario33

82




82




New contributor




Mario33 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Mario33 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Mario33 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • This is possible, yes: you read the content of that file, parse it as directory names and filenames, and do something with it.
    – Dominique
    Nov 9 at 12:27










  • Hi @Dominique, thanks for your reply, can you help me with this? Thanks
    – Mario33
    Nov 9 at 12:32







  • 1




    @Dominique downvoting my answer does not solve the fact that you posted incorrectly in the previous question, I suggest you learn a litle more about this site. Ignorance is going to bring you nowhere.
    – Gerhard Barnard
    Nov 9 at 12:39

















  • This is possible, yes: you read the content of that file, parse it as directory names and filenames, and do something with it.
    – Dominique
    Nov 9 at 12:27










  • Hi @Dominique, thanks for your reply, can you help me with this? Thanks
    – Mario33
    Nov 9 at 12:32







  • 1




    @Dominique downvoting my answer does not solve the fact that you posted incorrectly in the previous question, I suggest you learn a litle more about this site. Ignorance is going to bring you nowhere.
    – Gerhard Barnard
    Nov 9 at 12:39
















This is possible, yes: you read the content of that file, parse it as directory names and filenames, and do something with it.
– Dominique
Nov 9 at 12:27




This is possible, yes: you read the content of that file, parse it as directory names and filenames, and do something with it.
– Dominique
Nov 9 at 12:27












Hi @Dominique, thanks for your reply, can you help me with this? Thanks
– Mario33
Nov 9 at 12:32





Hi @Dominique, thanks for your reply, can you help me with this? Thanks
– Mario33
Nov 9 at 12:32





1




1




@Dominique downvoting my answer does not solve the fact that you posted incorrectly in the previous question, I suggest you learn a litle more about this site. Ignorance is going to bring you nowhere.
– Gerhard Barnard
Nov 9 at 12:39





@Dominique downvoting my answer does not solve the fact that you posted incorrectly in the previous question, I suggest you learn a litle more about this site. Ignorance is going to bring you nowhere.
– Gerhard Barnard
Nov 9 at 12:39













1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










You would run a for loop and split on the , delimeter and use each as a variable.



So as an untested example, here I will split the file entries and assign 2 tokens %%i and %%j



@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo "%%i" "%%j"


Note that I added a double quotes to the tokens as it will possibly contain spaces.



Seeing that you want to do a delete, it will probably be something like:



@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo del "%%j%%i"


Where you would just remove the echo to perform the actual delete.



As per your comment, to skip the first line and exclude the **rows affected line you can use:



for /f "tokens=1,2 skip=1 delims=," %i in ('more my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"


alternatively seeing that you are using more, you can exclude skip=1 and simply use +1 on the mroe command.



for /f "tokens=1,2 delims=," %i in ('more +1 my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"





share|improve this answer






















  • Hi @gerhard I will try to do this and I'll come back to inform the result. Many thanks
    – Mario33
    Nov 9 at 12:52











  • All good, let me know about that trailing space after the comma as well so I can make changes if needed.
    – Gerhard Barnard
    Nov 9 at 12:52










  • You can strip off leading spaces with another for /f "tokens=*" %%x in ("%%j") do ...
    – LotPings
    Nov 9 at 13:05






  • 1




    @LotPings. Yes thank you. I however doubt it does contain a space based on my numerous csv file exports from DB's :) but could build it in as a fail safe regardless.
    – Gerhard Barnard
    Nov 9 at 13:08











  • @GerhardBarnard works very well :D many thanks. Only one more question, Can I skip the first line? I try to insert in the same FOR for /f "skip=1" "tokens=1,2 delims=," %%i in (my_file.txt) do del "%%j%%i" and does not work, probably it is wrong. I need to create a new FOR to skip the first line? And them I can ignore the text (xx Rows affected) in my_file.txt? I'm sorry for all the question, I'm new in batch. Thanks for all your help.
    – Mario33
    Nov 9 at 13:44











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Mario33 is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53225597%2fdelete-a-files-with-their-name-and-path-in-another-file-bat%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










You would run a for loop and split on the , delimeter and use each as a variable.



So as an untested example, here I will split the file entries and assign 2 tokens %%i and %%j



@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo "%%i" "%%j"


Note that I added a double quotes to the tokens as it will possibly contain spaces.



Seeing that you want to do a delete, it will probably be something like:



@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo del "%%j%%i"


Where you would just remove the echo to perform the actual delete.



As per your comment, to skip the first line and exclude the **rows affected line you can use:



for /f "tokens=1,2 skip=1 delims=," %i in ('more my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"


alternatively seeing that you are using more, you can exclude skip=1 and simply use +1 on the mroe command.



for /f "tokens=1,2 delims=," %i in ('more +1 my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"





share|improve this answer






















  • Hi @gerhard I will try to do this and I'll come back to inform the result. Many thanks
    – Mario33
    Nov 9 at 12:52











  • All good, let me know about that trailing space after the comma as well so I can make changes if needed.
    – Gerhard Barnard
    Nov 9 at 12:52










  • You can strip off leading spaces with another for /f "tokens=*" %%x in ("%%j") do ...
    – LotPings
    Nov 9 at 13:05






  • 1




    @LotPings. Yes thank you. I however doubt it does contain a space based on my numerous csv file exports from DB's :) but could build it in as a fail safe regardless.
    – Gerhard Barnard
    Nov 9 at 13:08











  • @GerhardBarnard works very well :D many thanks. Only one more question, Can I skip the first line? I try to insert in the same FOR for /f "skip=1" "tokens=1,2 delims=," %%i in (my_file.txt) do del "%%j%%i" and does not work, probably it is wrong. I need to create a new FOR to skip the first line? And them I can ignore the text (xx Rows affected) in my_file.txt? I'm sorry for all the question, I'm new in batch. Thanks for all your help.
    – Mario33
    Nov 9 at 13:44















up vote
0
down vote



accepted










You would run a for loop and split on the , delimeter and use each as a variable.



So as an untested example, here I will split the file entries and assign 2 tokens %%i and %%j



@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo "%%i" "%%j"


Note that I added a double quotes to the tokens as it will possibly contain spaces.



Seeing that you want to do a delete, it will probably be something like:



@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo del "%%j%%i"


Where you would just remove the echo to perform the actual delete.



As per your comment, to skip the first line and exclude the **rows affected line you can use:



for /f "tokens=1,2 skip=1 delims=," %i in ('more my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"


alternatively seeing that you are using more, you can exclude skip=1 and simply use +1 on the mroe command.



for /f "tokens=1,2 delims=," %i in ('more +1 my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"





share|improve this answer






















  • Hi @gerhard I will try to do this and I'll come back to inform the result. Many thanks
    – Mario33
    Nov 9 at 12:52











  • All good, let me know about that trailing space after the comma as well so I can make changes if needed.
    – Gerhard Barnard
    Nov 9 at 12:52










  • You can strip off leading spaces with another for /f "tokens=*" %%x in ("%%j") do ...
    – LotPings
    Nov 9 at 13:05






  • 1




    @LotPings. Yes thank you. I however doubt it does contain a space based on my numerous csv file exports from DB's :) but could build it in as a fail safe regardless.
    – Gerhard Barnard
    Nov 9 at 13:08











  • @GerhardBarnard works very well :D many thanks. Only one more question, Can I skip the first line? I try to insert in the same FOR for /f "skip=1" "tokens=1,2 delims=," %%i in (my_file.txt) do del "%%j%%i" and does not work, probably it is wrong. I need to create a new FOR to skip the first line? And them I can ignore the text (xx Rows affected) in my_file.txt? I'm sorry for all the question, I'm new in batch. Thanks for all your help.
    – Mario33
    Nov 9 at 13:44













up vote
0
down vote



accepted







up vote
0
down vote



accepted






You would run a for loop and split on the , delimeter and use each as a variable.



So as an untested example, here I will split the file entries and assign 2 tokens %%i and %%j



@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo "%%i" "%%j"


Note that I added a double quotes to the tokens as it will possibly contain spaces.



Seeing that you want to do a delete, it will probably be something like:



@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo del "%%j%%i"


Where you would just remove the echo to perform the actual delete.



As per your comment, to skip the first line and exclude the **rows affected line you can use:



for /f "tokens=1,2 skip=1 delims=," %i in ('more my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"


alternatively seeing that you are using more, you can exclude skip=1 and simply use +1 on the mroe command.



for /f "tokens=1,2 delims=," %i in ('more +1 my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"





share|improve this answer














You would run a for loop and split on the , delimeter and use each as a variable.



So as an untested example, here I will split the file entries and assign 2 tokens %%i and %%j



@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo "%%i" "%%j"


Note that I added a double quotes to the tokens as it will possibly contain spaces.



Seeing that you want to do a delete, it will probably be something like:



@echo off
for /f "tokens=1,2 delims=," %%i in (my_file.txt) do echo del "%%j%%i"


Where you would just remove the echo to perform the actual delete.



As per your comment, to skip the first line and exclude the **rows affected line you can use:



for /f "tokens=1,2 skip=1 delims=," %i in ('more my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"


alternatively seeing that you are using more, you can exclude skip=1 and simply use +1 on the mroe command.



for /f "tokens=1,2 delims=," %i in ('more +1 my_file.txt ^| findstr /VI /C:"rows affected"') do del "%%j%%i"






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 9 at 14:09

























answered Nov 9 at 12:33









Gerhard Barnard

6,44731030




6,44731030











  • Hi @gerhard I will try to do this and I'll come back to inform the result. Many thanks
    – Mario33
    Nov 9 at 12:52











  • All good, let me know about that trailing space after the comma as well so I can make changes if needed.
    – Gerhard Barnard
    Nov 9 at 12:52










  • You can strip off leading spaces with another for /f "tokens=*" %%x in ("%%j") do ...
    – LotPings
    Nov 9 at 13:05






  • 1




    @LotPings. Yes thank you. I however doubt it does contain a space based on my numerous csv file exports from DB's :) but could build it in as a fail safe regardless.
    – Gerhard Barnard
    Nov 9 at 13:08











  • @GerhardBarnard works very well :D many thanks. Only one more question, Can I skip the first line? I try to insert in the same FOR for /f "skip=1" "tokens=1,2 delims=," %%i in (my_file.txt) do del "%%j%%i" and does not work, probably it is wrong. I need to create a new FOR to skip the first line? And them I can ignore the text (xx Rows affected) in my_file.txt? I'm sorry for all the question, I'm new in batch. Thanks for all your help.
    – Mario33
    Nov 9 at 13:44

















  • Hi @gerhard I will try to do this and I'll come back to inform the result. Many thanks
    – Mario33
    Nov 9 at 12:52











  • All good, let me know about that trailing space after the comma as well so I can make changes if needed.
    – Gerhard Barnard
    Nov 9 at 12:52










  • You can strip off leading spaces with another for /f "tokens=*" %%x in ("%%j") do ...
    – LotPings
    Nov 9 at 13:05






  • 1




    @LotPings. Yes thank you. I however doubt it does contain a space based on my numerous csv file exports from DB's :) but could build it in as a fail safe regardless.
    – Gerhard Barnard
    Nov 9 at 13:08











  • @GerhardBarnard works very well :D many thanks. Only one more question, Can I skip the first line? I try to insert in the same FOR for /f "skip=1" "tokens=1,2 delims=," %%i in (my_file.txt) do del "%%j%%i" and does not work, probably it is wrong. I need to create a new FOR to skip the first line? And them I can ignore the text (xx Rows affected) in my_file.txt? I'm sorry for all the question, I'm new in batch. Thanks for all your help.
    – Mario33
    Nov 9 at 13:44
















Hi @gerhard I will try to do this and I'll come back to inform the result. Many thanks
– Mario33
Nov 9 at 12:52





Hi @gerhard I will try to do this and I'll come back to inform the result. Many thanks
– Mario33
Nov 9 at 12:52













All good, let me know about that trailing space after the comma as well so I can make changes if needed.
– Gerhard Barnard
Nov 9 at 12:52




All good, let me know about that trailing space after the comma as well so I can make changes if needed.
– Gerhard Barnard
Nov 9 at 12:52












You can strip off leading spaces with another for /f "tokens=*" %%x in ("%%j") do ...
– LotPings
Nov 9 at 13:05




You can strip off leading spaces with another for /f "tokens=*" %%x in ("%%j") do ...
– LotPings
Nov 9 at 13:05




1




1




@LotPings. Yes thank you. I however doubt it does contain a space based on my numerous csv file exports from DB's :) but could build it in as a fail safe regardless.
– Gerhard Barnard
Nov 9 at 13:08





@LotPings. Yes thank you. I however doubt it does contain a space based on my numerous csv file exports from DB's :) but could build it in as a fail safe regardless.
– Gerhard Barnard
Nov 9 at 13:08













@GerhardBarnard works very well :D many thanks. Only one more question, Can I skip the first line? I try to insert in the same FOR for /f "skip=1" "tokens=1,2 delims=," %%i in (my_file.txt) do del "%%j%%i" and does not work, probably it is wrong. I need to create a new FOR to skip the first line? And them I can ignore the text (xx Rows affected) in my_file.txt? I'm sorry for all the question, I'm new in batch. Thanks for all your help.
– Mario33
Nov 9 at 13:44





@GerhardBarnard works very well :D many thanks. Only one more question, Can I skip the first line? I try to insert in the same FOR for /f "skip=1" "tokens=1,2 delims=," %%i in (my_file.txt) do del "%%j%%i" and does not work, probably it is wrong. I need to create a new FOR to skip the first line? And them I can ignore the text (xx Rows affected) in my_file.txt? I'm sorry for all the question, I'm new in batch. Thanks for all your help.
– Mario33
Nov 9 at 13:44











Mario33 is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















Mario33 is a new contributor. Be nice, and check out our Code of Conduct.












Mario33 is a new contributor. Be nice, and check out our Code of Conduct.











Mario33 is a new contributor. Be nice, and check out our Code of Conduct.













 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53225597%2fdelete-a-files-with-their-name-and-path-in-another-file-bat%23new-answer', 'question_page');

);

Post as a guest














































































Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo