You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the destination path is a directory, the file will be copied into that directory as usual. If the destination path is a filename, the file will be copied and renamed.
124
124
125
+
---
126
+
127
+
### Rename Multiple Files During Copy
128
+
129
+
#### 1. Rename Using Glob Patterns
130
+
131
+
You can use a wildcard (`*`) in the destination to rename files dynamically. For example, to copy all `.css` files and change their extension to `.scss`:
132
+
133
+
```bash
134
+
copyfiles "input/**/*.css""output/*.scss"
135
+
```
136
+
137
+
This will copy:
138
+
139
+
- `input/foo.css` → `output/foo.scss`
140
+
- `input/bar/baz.css` → `output/bar/baz.scss`
141
+
142
+
The `*`in the destination is replaced with the base filename from the source.
143
+
You can combine this with `--flat` or `--up` to control the output structure.
144
+
145
+
#### 2. Rename Using a Callback (JavaScript API)
146
+
147
+
For advanced renaming, you can use the `rename` callback option in the API.
148
+
This functionreceives the source and destination path and should return the new destination path.
149
+
150
+
**Example: Change extension to `.scss` using a callback**
The `rename` callback gives you full control over the output filename and path.
176
+
177
+
>**Tip:**
178
+
> You can use either the glob pattern approach or the `rename` callback, or even combine them for advanced scenarios!
179
+
180
+
> [!NOTE]
181
+
> If you use both a destination glob pattern (e.g. `output/*.ext`) and a `rename` callback, the glob pattern is applied first and then the `rename` callback is executed last on the computed destination path. This allows you to combine both features for advanced renaming scenarios.
182
+
183
+
---
184
+
125
185
### JavaScript API
126
186
127
187
```js
@@ -136,11 +196,12 @@ and finally the third and last argument is a callback function which is executed
136
196
137
197
```js
138
198
{
139
-
verbose: bool, // enable debug messages
140
-
up: number, // -u value
141
-
exclude: string, // exclude pattern
142
-
all: bool, // include dot files
143
-
follow: bool, // Follow symlinked directories when expanding ** patterns
144
-
error: bool // raise errors if no files copied
199
+
verbose: bool, // enable debug messages
200
+
up: number, // -u value
201
+
exclude: string, // exclude pattern
202
+
all: bool, // include dot files
203
+
follow: bool, // follow symlinked directories when expanding ** patterns
204
+
error: bool // raise errors if no files copied
205
+
rename: (src, dest) => string; // callback to transform the destination filename(s)
0 commit comments