I am needing some assistance trying to figure out this batch file.
I am trying to rename the folders inside of the "TARGETFOLDER" from the "TARGETFOLDER.txt"
Here is my Batch File:
for /d %%f in (TARGETFOLDER\*) do rename "%%f" TARGETFOLDER.txt
For testing purposes I have 1 folder inside TARGETFOLDER named TEST1.
I have the TARGETFOLDER.txt with 1 line that says TEST2, in work directory.
What I am ending up with is the folder inside the TARGETFOLDER is getting renamed to "TARGETFOLDER.txt" and not renamed to TEST2.
Any Assistance would be Greatful!
Related
First, I should mention that have a windows machine.
Now, I want to copy files that have until as some part of their file names.
I have a folder named my data. I have several folders in it where they have four digits in the end of their names, such as my_folder_0000. I would like to find these folders, and copy the file with until being some part of their file names into another folder.
To clarify, please see the following example to better understand the structure:
my data/
|-- /my_folder_0000/my_file_until_2010.csv
|-- /his_folder_0001/his_file_until_2011.csv
|-- /test
|-- /documents
In the above example, I would like to go through the first two folders, copy the files into my folder on desktop.
I would like to have a script which works for windows. Thank you!
This should give you an idea how to do it:
#echo off& setlocal
for /d %%d in ("%~1\*.*") do set dir=%%d& call :next_dir %2
exit /b
:next_dir
for /f "delims=0123456789" %%i in ("%dir:~-4%") do exit /b
copy /y "%dir%\*until*.*" %1 | find "until"
At command line 1st arg is source directory (perhaps "\my data" in your case) and 2nd argument is destination directory for the copied files.
Existing/duplicate-named files are overwritten in destination without prompting. Filenames are displayed as they are copied.
I have a lot of files in one folder that I want to move to another folder. I have the files I want moved listed in a text file. Is there a way I can make a .bat so the files listed in the text file get moved to another folder?
I found this https://superuser.com/questions/355584/how-to-delete-files-from-a-folder-using-a-list-of-file-names-in-windows where this code
for /f "delims=" %%f in (files_to_delete.txt) do del "%%f"
sort of does I want, meaning that the batch uses a text file to process files, except it deletes the files. How do I modify this code so the files are moved to another folder?
Another question, the above code deletes files without going through the recycling bin. So how do I modify the code so when it deletes, the files get moved to the recycling bin. If that happens, then I can easily drag it out to a new folder. I'm a newb using Windows 10. Thank you.
I've been searching around how to make a batch file that works in it's current folder that it was executed. Then uses a filelist.txt along with the batch in that same folder to delete the files listed in that filelist.txt
It boils down like this
I run the batch file -> Batch file uses current folder it is in -> Uses filelist.txt the batch file is with -> batch file deletes the files listed in the filelist.txt
Help will be greatly appreciated..
By default, the batch file will run in its current directory.
What you are asking can be accomplished with one line.
for /f %%i in (filelist.txt) do if exist %%i del %%i
If the files are in different folders you will need to specify the full path for each file in filelist.txt
ex.
C:\users\Johndoe\desktop\picture1.jpg
C:\users\Johndoe\documents\picture2.jpg
i'm new to the forum. I need some advice. I need help with a code to take a text file with a list of file names and copy the files from multiple folders in to one folder, but it has to end up with the most recent modified date of the file. There are hundreds of folders containing the thousands of files.
I have a batch code below to copy the files, but it does not always end up with the newest file. If there is some way to make the code below search the folders in numerical order, that would work instead of it searching in a random order. I do not care if the code i end up using is batch, vbs, or whatever.
mkdir %userprofile%\desktop\print
set FIILELIST=%userprofile%\desktop\print.txt
set FILESPATH="\\server\folder"
set DESTPATH=%userprofile%\desktop\print
for /f %%X in (%FIILELIST%) do call :COPY_FILES "%%X"
goto :eof
:COPY_FILES
for /r %FILESPATH% %%I in (%~1) do copy "%%I" "%DESTPATH%"
for /r %FILESPATH% %%I in (%~1) do Xcopy /D "%%I" "%DESTPATH%"
XCOPY /D will only copy if the destination file does not exist or if the destination file is older than the source.
I am a CAD manager in need of some help. I am no programmer, but I have a very basic understanding of DOS commands so I thought I could use XCOPY to do this, but I don't know how.
I have a folder, under which are hundreds of subfolders that change with time (each employee has one folder) so maintaining a manual listing (as I have been doing) is not easy.
I also have a _TEMPLATE subfolder that contains several files and folders.
I would like to copy the contents of the _TEMPLATE folder into all the other subfolders, overwriting all existing files and creating all non-existing folders.
From what I've seen with some searching in here it seems to pretty easy to accomplish these two tasks (to create the list of folders and to copy into a list of folders) but I'm just too dumb to understand how to combine the two into one file :)
EDIT :
Well, I've found a PowerShell script that does what I need perfectly. Since I managed to run the PowerShell I guess my problem is solved :D
$folder = Get-Childitem -name -exclude *.*,_TEMPLATE
foreach ($f in $folder)
{xcopy "_TEMPLATE\*.*" "$f" /e /r /y }
Thanks for all the fish ;)
Try this:
#echo off &setlocal
cd /d "RootFolder=X:\folder\to\my data"
for /d %%a in (*) do xcopy "_TEMPLATE" "%%~fa" /sihrky
For xcopy options see xcopy /?, to test the command without writing add option /l.