Deprecated: Creation of dynamic property Timber\Site::$pingback is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Site.php on line 180

Deprecated: Creation of dynamic property Timber\User::$name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/User.php on line 118

Deprecated: Creation of dynamic property Timber\Post::$old_id is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_thumbnail_id is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$ext-thumbnail_url is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_edit_last is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_metadesc is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_date_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$ping_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_password is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$to_ping is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$pinged is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_content_filtered is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$guid is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$menu_order is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_mime_type is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_count is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$filter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71
Copiare in un'unica directory i file contenuti in un insieme di sottocartelle | IlSoftware.it

Copiare in un'unica directory i file contenuti in un insieme di sottocartelle

Problema: com'è possibile, in ambiente Windows, copiare tutti i file contenuti in un gruppo di sottocartelle all'interno di un'unica directory? Si supponga di avere N file, di qualunque tipologia, distribuiti in una una serie di sottocartelle...

Problema: com’è possibile, in ambiente Windows, copiare tutti i file contenuti in un gruppo di sottocartelle all’interno di un’unica directory?
Si supponga di avere N file, di qualunque tipologia, distribuiti in una una serie di sottocartelle “nidificate” tra loro. Come si può recuperare tutti i file contenuti nelle varie sottodirectory e memorizzarli all’interno di una medesima cartella?

Le soluzioni sono molteplici anche se per un’operazione come questa si può evitare di dover ricorrere ad un software sviluppato da terze parti.
Proponiamo quindi, di seguito, un approccio basato sull’utilizzo di uno script VBS.

si potrà editarlo con il Blocco Note di Windows (in alternativa è possibile ricorrere a qualunque altro editor di testo).

si dovrà incollare quanto segue:

Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "c:\lavori\dir"
strDestination = "c:\temp\dir"

if right(strFolder,1)"\" then strFolder = strFolder & "\"
if right(strDestination,1)"\" then strDestination = strDestination & "\"

Set objFolder = objFS.GetFolder(strFolder)

Go(objFolder)

Sub Go(objDIR)
   If objDIR "\System Volume Information" Then
      For Each eFolder in objDIR.SubFolders
         Go eFolder
      Next
      For Each strFile In objDIR.Files
         strFileName = strFile.Name
         strExtension = objFS.GetExtensionName(strFile)
         If strExtension = "xls" Then
            if objFS.FileExists(strDestination & strFileName) then
               strFileName = objDIR.Name & "_" & strFileName
            end if
            objFS.CopyFile strFile , strDestination & strFileName
         End If
      Next
   End If
End Sub

(cartella di destinazione).
Lo script VBS provvederà a copiare il contenuto di tutte le sottocartelle presenti nella directory strFolder salvandole poi nella cartella strDestination.

Com’è possibile verificare, lo script impiega poi un algoritmo ricorsivo per “scansionare” tutte le sottocartelle contenute nella directory di origine.

Nel caso in cui il file dovesse esistere già nella cartella di destinazione, il nome del file omonimo verrà modificato ponendo come prefisso il nome della directory che lo contiene (istruzione strFileName = objDIR.Name & "_" & strFileName).

Per come è stato sviluppato lo script, saranno copiati – dalla cartella di origine – solo i file con estensione xls. Ovviamente è possibile specificare un’altra estensione oppure personalizzare liberamente il blocco if (esempio: If strExtension = "xls" or strExtension = "doc" Then). La if può essere completamente eliminata nel caso in cui si desiderino copiare tutti i file, di qualunque tipologia.

.

Suggeriamo di utilizzare il file VBS solo dopo averne ben compreso il funzionamento. In ogni caso è preferibile effettuare sempre almeno una copia di backup dei dati sui quali si intende operare.

Ti consigliamo anche

Link copiato negli appunti