Batch file Copy Folder specified in a .txt file - text

I'm looking for batch file code that will copy folders specified in a text file.
So in the text file
C:\User\
C:\Random\Random\Random
and so on.
The destination will be set at N:\Backups\PC
Thanks

set dest=N:\Backups\PC
for /f %%i in (C:\dirs.txt) do copy "%%i" %dest%

Related

Pass list of file paths to a batch file to be copied from Location A to Location B

Beginner to batch files and running commands in cmd or PowerShell. Need help in writing a script and/or producing a batch file that will allow me to do the following:
1) Pull list (List1) of file paths (including the file name and where the file is saved currently) from ColumnA of Excel123.xslx and a list (List2) of new destination file paths from ColumnB of Excel123.xlsx (if needed, the file with the old path and destination path can be in CSV or any txt format)
2) Pass through the file paths from List1 and copy the file from the location in List1 to the new destination location in List2
In fewer words, I need to copy a file from the current location in List1 to the new destination location in List2. And, if the new destination location includes folders and sub-folders that do not exist yet, they need to be created in the process.
Any advice/insight? Thank you!
I believe you are looking to essentially do as follows:
#(SETLOCAL
ECHO OFF
SET "_CSV_File=C:\Some\Path\FileList.csv"
)
FOR /F "Tokens=1-2 Delims=," %%A IN ('
Type %_CSV_File% ') DO (
ECHO: Copying FROM: "%%~A" TO: "%%~B"
COPY /B /V /Y /Z "%%~A" "%%~B"
)
ENDLOCAL

How to loop through a directory and skip folders containing a specific string?

I am currently scanning an entire directory, copying an exe over and running it in each folder. This exe converts certain log files within each folder. However, half the directories don't contain any log files and it seems like a waste to move into each of those folders and run an exe that does nothing. An example of some folder names:
0075D-S10
0075D-S10-EVT
0132C-S10
0132C-S10-EVT
and so on...
I basically only need to copy the executable into the folders that don't contain EVT in the name. These just contain evtx files that aren't important to me at the moment.
Here is a snippet of my batch file and what it is doing:
set back=%cd%
set current_dir=%cd%
setlocal EnableDelayedExpansion
for /d %%i in ("%current_dir%\*") do (
copy LogCsv.exe "%%i" >NULL
cd "%%i"
LogCsv.exe
)
cd %back%
Really my first time just using Batch files and I've been exploring answers on here, but couldn't find a solution to this particular problem. How can I loop this directory, excluding any folders containing the "EVT" string in their name?
Thanks for taking time to assist!
Well, you can use findstr /v to exclude certain values from search results.
#echo off
set back=%cd%
set current_dir=%cd%
for /f %%i in ('dir /b /ad %current_dir%\* ^| findstr /v EVT') do (
copy LogCsv.exe "%%i" >NUL
cd "%%i"
LogCsv.exe
cd %back%
)
Also note, you need to pipe to nul not null

Batch - Find string in text file and delete full line

I use the script from this Thread accepted answer from Mofi. The script copy folders and store them in text file to exclude once copied folders on next run.
Sometimes I have folders called [incomplete]-different.names and I do not want to copy this folders. I want that all folders with the string [incomplete]- and the name behind are skipped or are not even written in the text file %CurrentList% for further processing.
These are my previous attempts but so far I could not get up and running with the script from the top.
Help would be nice, and thanks in advance.
Try 1:
for /f "delims=" [incomplete]-%%D in ("%CurrentList%") do (
set str=%%D
set str=!str: =!
set str=!str: %%D =!
echo !str!
Try 2:
findstr /v /b /c:"[incomplete]-"%%D" "%CurrentList%" del "%%D"
You were really close with your second attempt.
If all you want is to delete lines in %CurrentList% that contain the string [incomplete]-, you can just direct the output of a findstr /v to a temp file and then overwrite CurrentList with that file.
findstr /v /c:"[incomplete]-" "%CurrentList%" >tmpList.txt
move /y tmpList.txt "%CurrentList%" >nul

Batch script to change many .xlsx files to .csv

I have a folder with many subfolders (1000+) and inside the subfolders are a few excel files, in .xlsx format. I want to run a batch script from the main folder, which goes into each sub folder and changes each .xlsx Excel file into a .csv Excel file.
The formatting of the file system:
MainFolder
---subfolder1
----->file1.xlsx
---subfolder2
----->file2.xlsx
etc.
From this thread: Convert XLS to CSV on command line, I figured out that I can't just rename each .xlsx to .csv, so I made the ExceltoCSV.vbs file (the modified ScottF answer, second one down). My understanding is that I can make a for loop in a batch file to run ExceltoCSV.vbs for each sub folder. The following line of code is something i attempted, but it didn't work. It usually says *.xlsx file is not found.
for /R %%F in ("C:\MainFolder") do cscript ExceltoCSV.vbs *.xlsx *.csv
Also tried this:
for /d /r "C:\MainFolder" %%F in (.) do cscript ExceltoCSV.vbs "%%F\*.xlsx" *.csv
Error message:
C:\MainFolder\ExceltoCSV.vbs(17,1) Microsoft Excel: 'C:\MainFolder\folder1\*.xlsx' could not be found. Check the spelling of the file name, and verify that the file location is correct.
The VBS script you got from SO only takes a string as an input. What you'll need to do is create a loop with a regex pattern that builds those file names dynamically and then run the script with an input string representing each file name. Pseudo code:
for loop (iterate over file names in dir){
set $file_name=$iterated_file_name_from_loop
ExceltoCSV.vbs "$file_name.xlsx" *.csv
}

move files name in excel to a specific folder

I am trying to write a batch file that reads from excel file. then move them to a specique folder.
lets say in the excel , there are:
111.txt
222.txt
333.txt
512.txt
I want a batch file that move files into a specific directory that have the above names.
how can I achieve that ?
(I am using xp , and I the directory is D:)
cd /d "d:\files"
for /f %%i in ("C:\where the file resides\file.csv") do (
echo move "%%i" "D:\New\"
)
remove the echo if output seems ok

Resources