Jump to content

Only Copy Dxf and PDF from Directory


Recommended Posts

is there a way to just copy the (DXF PDF ) files from a directory to a different location

 

So like this

Open folder C:\Test\   look inside folder

 

Copy all folder inside c:\test\  to D:\test \

make the folder names the same .

Copy only the files *.DXF and *.PDF to that correct  folders.

Link to post
Share on other sites
  • Developers

Yes that is pretty easy to do. Just open the Helpfile and start reading about and playing with UDF: _FileListToArray()

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites

Welcome to AutoIt and the forum!

Should be easy. Please have a look at _FileListToArrayRec in the help file on how to get a list of files to copy.
Then loop through the array and use FileCopy for each file.

Edit: Too slow ;)

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites

If I understood correctly, OP would like to :
1) Recreate his folder structure from C:\Test to D:\Test ("make the folder names the same")
2) Then copy *.DXF and *.PDF files to the appropriate folders

I tried it with Xcopy (which exists in all Windows releases), here is an example for pdf files :

RunWait(@ComSpec & " /c Xcopy C:\Test\*.pdf D:\Test\ /s /e /y", "", @SW_HIDE)
If @error Then MsgBox(0, "", "bad lemonade")

Explanation for Xcopy parameters :
/s take care of subdirectories too...
/e ... even if they are empty
/y suppress prompting to confirm that you want to overwrite an existing destination file.

I just tried it with a test folder structure containing subdirectories (empty or filled with several types of files) and it worked fine :
1) The directory structure was recreated (even the empty subfolders)
2) Only the *.pdf files were copied to their correct locations.

Edited by pixelsearch
Changed Run to RunWait (help file)
Link to post
Share on other sites

If you want to copy all types of files in a single copy, you could use robocopy (robust copy) :

#include <Constants.au3>
#include <WinAPIConv.au3>

$iPID = Run(@ComSpec & ' /c robocopy "c:\apps\temp" "c:\apps\back" *.PDF *.DXF /s /v', "", @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($iPID)
$sText = StdoutRead($iPID)
ConsoleWrite (_WinAPI_OemToChar($sText) & @CRLF)

You can get a full report of the job and save it if you want...

Link to post
Share on other sites

Thank you for the reply's  this is good i can use this  Thank you

can you also make a filter to only  select the folders that start withe the string 2021 

Like  Folder Name (2021 top)

Edited by Steal45
Link to post
Share on other sites
6 hours ago, Steal45 said:

can you also make a filter to only  select the folders that start withe the string 2021

Not with robocopy itself.  You would need to use _FileListToArrayRec to search for all folders starting with 2021 in the directory tree.  Then for each folder found use the robocopy to copy all files :

#include <Constants.au3>
#include <WinAPIConv.au3>
#include <File.au3>

Local $aFolder = _FileListToArrayRec("c:\Apps", "2021*", $FLTAR_FOLDERS, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_RELPATH)
If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","No folder found")
Local $iPID, $sResult
For $i = 1 to $aFolder[0]
  $iPID = Run(@ComSpec & ' /c robocopy "c:\Apps\' & $aFolder[$i] & '" "c:\Apps\Backup\' & $aFolder[$i] & '" *.PDF *.DXF /v', "", @SW_HIDE, $STDOUT_CHILD)
  ProcessWaitClose($iPID)
  $sResult &= StdoutRead($iPID) & @CRLF
Next
ConsoleWrite (_WinAPI_OemToChar($sResult))

 

Edited by Nine
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...